ORA-06512 ORA-06503: PL/SQL: Function returned without value

Error Description:
Select from the oracle function return the following error
SQL> select fib(3) from dual;
       *
ERROR at line 1:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "STHOMAS.FIB", line 4
Solution Description:

A function must return a value when you select from the same. You have to check whether the function PLSQL code whether it is going for any exception and it is not returning any values at the end. At least a null value “return null” will fix the issue.

Here is one example:

SQL> create or replace function fib (x number) return number as
begin
        dbms_output.put_line('x');
end;
 /

Function created.

SQL>
SQL> set serveroutput on
select fib(3) from dual
       *
ERROR at line 1:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "STHOMAS.FIB", line 4
 
Fix:
SQL> create or replace function fib (x number) return number as
begin
        dbms_output.put_line('x');
        return null;
end; 
/

Function created.

SQL>  select fib(3) from dual;
    FIB(3)
----------

X

No comments:

Post a Comment