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!

Why NVL2 doesn't work in PL/SQL block?

Blue BirdJul 6 2018 — edited Jul 6 2018

Hi,

I would like to use NVL2 function inside PL/SQL (actually I need it inside Cursor For loop, but in this simplified example doesn't work either) block but I get error PLS-00201: identifier 'NVL2' must be declared when I run script. Similar NVL works Ok. If I use NVL2 inside stand alone SQL statement (below) works ok. Why this doesn't work here and what builtin function I can use instead of this one so I can get same functionality if this cannot be used?

Declare

  v_Res1 VarChar2(1000) := 'SALESMAN';

  v_Res2 VarChar2(1000) := 'SALESMAN';

  v_Res3 VarChar2(1000) := 'SALESMAN';

Begin

    v_Res1 := NVL(v_Res1, 'Null');

    DBMS_OutPut.Put_Line('v_Res1: ' || v_Res1); -- Work Ok

    Select NVL2(v_Res2, 'NotNull', 'Null')

    Into v_Res2

    From Dual;

    DBMS_OutPut.Put_Line('v_Res2: ' || v_Res2); -- Work Ok

  

    v_Res3 := NVL2(v_Res3, 'NotNull', 'Null'); -- Why this doesn't work?

    DBMS_OutPut.Put_Line('v_Res3: ' || v_Res3);

End;

/

Select NVL2('SALESMAN', 'NotNull', 'Null')

From Dual; -- Work Ok

/

BB

This post has been answered by Cookiemonster76 on Jul 6 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2018
Added on Jul 6 2018
10 comments
3,870 views