Query Returning value as 0
- by NIMISH DESHPANDE
I am trying to execute following PL/SQL script in SQL Developer. The loop should return count of nulls but somehow everytime it is returning 0.
set serveroutput on
DECLARE
--v_count number;
v_count_null number;
BEGIN
execute immediate 'select count(*) from SP_MOSAIX' into v_count;
FOR i in (select column_name from all_tab_COLUMNS where table_name = 'SP_MOSAIX')
LOOP
select count(*) into v_count_null from SP_MOSAIX where i.column_name IS NULL ;
dbms_output.put_line(v_count_null);
END LOOP;
END;
So when I run this, following output is what i get:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
But if I manually execute the query subsituting column_name I get the result.
select count(*) into v_count_null from SP_MOSAIX where i.column_name IS NULL;
Can anybody help on this?