Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> nvl2() can not be used in a cursor?
I tried to use nvl2 in the select statement of a cursor declaration in
a procedure. It won't compile.
This is on "Oracle8i Enterprise Edition Release 8.1.7.4.0 -
Production"
spool of error reproduction:
SQL> set echo on SQL> @nvl2_test.sql SQL> create table test
Table created.
SQL>
SQL> insert into test (col1) values (1);
1 row created.
SQL> insert into test (col1,col2) values (2,'The other record is null');
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL>
SQL> select col1, col2, nvl(col2,'{NULL}') nvl_func from test;
COL1 COL2
---------- --------------------------------------------------NVL_FUNC
1
{NULL}
2 The other record is null
The other record is null
SQL> select col1, col2, nvl2(col2,'NOT NULL: '||col2,'{NULL}') nvl2_func from test;
COL1 COL2
---------- --------------------------------------------------NVL2_FUNC
1
{NULL}
2 The other record is null
NOT NULL: The other record is null
SQL>
SQL> create or replace procedure p_test is
2 cursor cur_nvl is select col1, col2, nvl(col2,'{NULL}')
nvl_func from test;
3 begin
4 for rec_nvl in cur_nvl loop 5 dbms_output.put_line(rec_nvl.nvl_func); 6 end loop;
Procedure created.
SQL> SQL> set serveroutput on SQL> execute p_test;
PL/SQL procedure successfully completed.
SQL>
SQL> create or replace procedure p_test is
2 cursor cur_nvl2 is select col1, col2, nvl2(col2,'NOT NULL:
'||col2,'{NULL}') nvl2_func from test;
3 begin
4 for rec_nvl2 in cur_nvl2 loop 5 dbms_output.put_line(rec_nvl2.nvl2_func); 6 end loop;
Warning: Procedure created with compilation errors.
SQL>
SQL> show errors
Errors for PROCEDURE P_TEST:
LINE/COL ERROR
-------- ----------------------------------------------------------------- 2/21 PL/SQL: SQL Statement ignored 2/40 PLS-00201: identifier 'NVL2' must be declared 5/3 PL/SQL: Statement ignored 5/24 PLS-00364: loop index variable 'REC_NVL2' use is invalid SQL> set serveroutput off SQL>