Query Returning value as 0

Posted by NIMISH DESHPANDE on Stack Overflow See other posts from Stack Overflow or by NIMISH DESHPANDE
Published on 2012-11-20T21:56:29Z Indexed on 2012/11/20 23:01 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle