I came across a scenario where I've seen that NVL2 is a PL/SQL function but when I tried to use this function directly with plsql variable it gives me error. Although it is working find within SQL.
Below is the sample I am posting its strange behaviour that I am seeing.
I am under banner PL/SQL Release 11.2.0.4.0 - Production
SQL> --See when we use NVL2 within SQL it works fine
SQL> select nvl2('IamNotNull', 'IamForNotNull', 'IamForNull') for_not_null
2 ,nvl2(null, 'IamForNotNull', 'IamForNull') for_null
3 from dual;
FOR_NOT_NULL FOR_NULL
------------- ----------
IamForNotNull IamForNull
SQL> --Problem occurs when we assign the resultant directly into variable in anonymous block
SQL> declare
2 for_not_null varchar2(200);
3 begin
4 for_not_null :=NVL2('IamNotNull', 'IamForNotNull', 'IamForNull');
5 end;
6 /
for_not_null :=NVL2('IamNotNull', 'IamForNotNull', 'IamForNull');
*
ERROR at line 4:
ORA-06550: line 4, column 20:
PLS-00201: identifier 'NVL2' must be declared
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
SQL>