What Is PLS-00222?
The PLS-00222 error means that PL/SQL could not find a function with the given name that is visible in the current scope. In simple terms, you’re trying to call a function that:
- Was not declared or created
- Is misspelled
- Is out of scope
- Has a wrong signature
- Was not compiled successfully
When Does It Occur?
You may encounter this error in the following situations:
- Calling a function that was never declared
- Calling a local function outside its scope
- Calling a function from a package but not qualifying it with the package name
- Using a function name that is overloaded improperly
- Compiling code when the function is invalid or missing
Common Scenarios and Fixed
Scenario 1: Function Not Declared
Example:
BEGIN
DBMS_OUTPUT.PUT_LINE(add_numbers(10, 20));
END;
/
Error:
PLS-00222: no function with name 'ADD_NUMBERS' exists in this scope
Fix:
Declare or define the function add_numbers
.
CREATE OR REPLACE FUNCTION add_numbers(a NUMBER, b NUMBER) RETURN NUMBER IS
BEGIN
RETURN a + b;
END;
/
BEGIN
DBMS_OUTPUT.PUT_LINE(add_numbers(10, 20));
END;
/
❌ Scenario 2: Misspelled Function Name
Example:
CREATE OR REPLACE FUNCTION calculate_sum(a NUMBER, b NUMBER) RETURN NUMBER IS
BEGIN
RETURN a + b;
END;
/
BEGIN
DBMS_OUTPUT.PUT_LINE(calclate_sum(10, 20)); -- Typo here
END;
/
Error:
PLS-00222: no function with name 'CALCLATE_SUM' exists in this scope
Fix:
Correct the spelling of the function name.
BEGIN
DBMS_OUTPUT.PUT_LINE(calculate_sum(10, 20)); -- Fixed spelling
END;
/
❌ Scenario 3: Function Declared in a Package But Called Without Qualification
Example:
-- Package spec
CREATE OR REPLACE PACKAGE math_utils IS
FUNCTION multiply(a NUMBER, b NUMBER) RETURN NUMBER;
END math_utils;
/
-- Package body
CREATE OR REPLACE PACKAGE BODY math_utils IS
FUNCTION multiply(a NUMBER, b NUMBER) RETURN NUMBER IS
BEGIN
RETURN a * b;
END;
END math_utils;
/
-- Calling without prefix
BEGIN
DBMS_OUTPUT.PUT_LINE(multiply(4, 5));
END;
/
Error:
PLS-00222: no function with name 'MULTIPLY' exists in this scope
Fix:
Qualify the function name with the package name.
BEGIN
DBMS_OUTPUT.PUT_LINE(math_utils.multiply(4, 5)); -- Fixed
END;
/
❌ Scenario 4: Overloaded Function with Ambiguous Signature
Example:
CREATE OR REPLACE FUNCTION test_func(p NUMBER) RETURN NUMBER IS
BEGIN
RETURN p * 2;
END;
/
CREATE OR REPLACE FUNCTION test_func(p VARCHAR2) RETURN NUMBER IS
BEGIN
RETURN LENGTH(p);
END;
/
BEGIN
DBMS_OUTPUT.PUT_LINE(test_func(NULL)); -- Ambiguous call
END;
/
Error:
PLS-00307: too many declarations of 'TEST_FUNC' match this call
PLS-00222: no function with name 'TEST_FUNC' exists in this scope
Fix:
Provide explicit casting to clarify which version to call.
BEGIN
DBMS_OUTPUT.PUT_LINE(test_func(CAST(NULL AS NUMBER))); -- Calls NUMBER version
DBMS_OUTPUT.PUT_LINE(test_func(CAST(NULL AS VARCHAR2))); -- Calls VARCHAR2 version
END;
/
❌ Scenario 5: Calling a Local Function Outside Its Scope
Example:
DECLARE
FUNCTION local_func RETURN VARCHAR2 IS
BEGIN
RETURN 'Hello from Local';
END;
BEGIN
END;
-- Outside of block
BEGIN
DBMS_OUTPUT.PUT_LINE(local_func()); -- Invalid scope
END;
/
Error:
PLS-00222: no function with name 'LOCAL_FUNC' exists in this scope
Fix:
You can only call local functions within the same block where they are declared.
BEGIN
DECLARE
FUNCTION local_func RETURN VARCHAR2 IS
BEGIN
RETURN 'Hello from Local';
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(local_func()); -- Valid call
END;
END;
/
Tips to Avoid PLS-00222
- Ensure the function exists and is compiled.
- Use proper scope—don’t call local functions from outside.
- Use correct package prefixes when needed.
- Avoid ambiguous overloading—add clarity with type casting.
- Check for typos in function names.
- Use
SHOW ERRORS
to see if your function failed to compile.
Conclusion
The PLS-00222 error is usually caused by scope, spelling, or calling conventions. Fixing it requires reviewing where and how the function is declared and making sure you are calling it from the correct place using the right syntax. Always keep your functions compiled, visible, and unambiguous.