Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can a function return null?

TinaSep 23 2016 — edited Sep 24 2016

Hi Gurus,

      I am trying to understand if an oracle function return NULL as a return?

      I have a function which returns null and I can invoke it in a select without error.

      Somewhere I read function shouldn't return a null or would get an error if used in a 'select statement' if it returns null.

      I just want to confirm if I am missing anything.

    

CREATE OR REPLACE FUNCTION MY_FNC(in_param IN varchar2) RETURN VARCHAR2 IS
         A VARCHAR2(30);
BEGIN
       SELECT O.OWNER INTO A  FROM ALL_OBJECTS O WHERE O.OBJECT_NAME = 'a';
       return a;
      DBMS_OUTPUT.PUT_LINE('a: '||a);
END;

select my_fnc('a') from dual;    

Thanks

This post has been answered by CarlosDLG on Sep 23 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2016
Added on Sep 23 2016
18 comments
14,775 views