Oracle 23.26PL/SQLLab-verified · 2026-11-30

ORA-06503: PL/SQL: function returned without value

A PL/SQL function reached its END without executing any RETURN statement.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-06503: PL/SQL: function returned without value

Jump to a cause

  1. 01IF/ELSIF with no RETURN for the remaining case
  2. 02An exception handler that logs but does not RETURN

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim

A function must end through a RETURN with a value. If execution reaches the final END without one, Oracle raises ORA-06503. The function still compiles, so the error appears only when a specific input takes the path that has no RETURN.

The ORA-06512 line under the error points to that END. Both cases below were run on Oracle 26ai Free.

01IF/ELSIF with no RETURN for the remaining case

grade_of returns 'A' for 90 or more and 'B' for 70 or more, but has no ELSE. grade_of(95) is fine; grade_of(50) falls through the IF and hits END, so the query fails with ORA-06503 at "LAB_A.GRADE_OF", line 8, which is the last line.

Adding RETURN 'C'; after END IF; made every path return a value. The same query then returned A and C.

Setup
Setuprun as lab_a
CREATE OR REPLACE FUNCTION grade_of(p_score NUMBER) RETURN VARCHAR2 IS
BEGIN
  IF p_score >= 90 THEN
    RETURN 'A';
  ELSIF p_score >= 70 THEN
    RETURN 'B';
  END IF;
END;
/
OUTPUT
Function created.
Reproducerun as lab_a
SELECT grade_of(95) AS g1, grade_of(50) AS g2 FROM dual;
✕ ERROR
SELECT grade_of(95) AS g1, grade_of(50) AS g2 FROM dual
                           *
ERROR at line 1:
ORA-06503: PL/SQL: function returned without value
ORA-06512: at "LAB_A.GRADE_OF", line 8
Help: https://docs.oracle.com/error-help/db/ora-06503/
Fixrun as lab_a
CREATE OR REPLACE FUNCTION grade_of(p_score NUMBER) RETURN VARCHAR2 IS
BEGIN
  IF p_score >= 90 THEN
    RETURN 'A';
  ELSIF p_score >= 70 THEN
    RETURN 'B';
  END IF;
  RETURN 'C';
END;
/
OUTPUT
Function created.

Put a RETURN at the end of the function, after the IF, so no path can reach END without one.

After the fixrun as lab_a
SELECT grade_of(95) AS g1, grade_of(50) AS g2 FROM dual;
✓ SUCCESS
G1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
G2
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
A
C


1 row selected.

02An exception handler that logs but does not RETURN

emp_name catches NO_DATA_FOUND and only calls DBMS_OUTPUT.PUT_LINE. For id 99 the handler printed not found: 99, then the function ended with no value and the caller got ORA-06503 at "LAB_A.EMP_NAME", line 9.

The NO_DATA_FOUND was handled, so this is not ORA-01403; the missing RETURN is the problem. Changing the handler to RETURN NULL; fixed it: the block printed (none) for id 99 and Kim for id 1.

Setup
Setuprun as lab_a
CREATE TABLE emp (id NUMBER PRIMARY KEY, name VARCHAR2(20));
INSERT INTO emp VALUES (1, 'Kim');
COMMIT;
CREATE OR REPLACE FUNCTION emp_name(p_id NUMBER) RETURN VARCHAR2 IS
  v VARCHAR2(20);
BEGIN
  SELECT name INTO v FROM emp WHERE id = p_id;
  RETURN v;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('not found: ' || p_id);
END;
/
OUTPUT
Table created.


1 row created.


Commit complete.


Function created.
Reproducerun as lab_a
SET SERVEROUTPUT ON
BEGIN
  DBMS_OUTPUT.PUT_LINE(NVL(emp_name(99), '(none)'));
END;
/
✕ ERROR
not found: 99
BEGIN
*
ERROR at line 1:
ORA-06503: PL/SQL: function returned without value
ORA-06512: at "LAB_A.EMP_NAME", line 9
ORA-06512: at line 2
Help: https://docs.oracle.com/error-help/db/ora-06503/
Fixrun as lab_a
CREATE OR REPLACE FUNCTION emp_name(p_id NUMBER) RETURN VARCHAR2 IS
  v VARCHAR2(20);
BEGIN
  SELECT name INTO v FROM emp WHERE id = p_id;
  RETURN v;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    RETURN NULL;
END;
/
OUTPUT
Function created.
After the fixrun as lab_a
SET SERVEROUTPUT ON
BEGIN
  DBMS_OUTPUT.PUT_LINE(NVL(emp_name(99), '(none)'));
  DBMS_OUTPUT.PUT_LINE(emp_name(1));
END;
/
✓ SUCCESS
(none)
Kim

PL/SQL procedure successfully completed.

FAQ

Why does my function compile but fail with ORA-06503?

The compiler does not require a RETURN on every path. The error happens at run time, only for inputs that reach END without a RETURN, like grade_of(50) here.

How do I find which line causes ORA-06503?

Look at the ORA-06512 line right after it. It points to the function's last line (END), which means execution got there without returning.

Do I need a RETURN in the EXCEPTION block of a function?

Yes. In the test, a handler that only printed a log line ended the function with no value and raised ORA-06503. Adding RETURN NULL; to the handler made the block print (none) with no error.

Is ORA-06503 the same as ORA-01403 no data found?

No. In the second case NO_DATA_FOUND was caught by the handler; ORA-06503 came afterwards because the handler did not return a value.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0