I have the following code which is supposed to find each column in a database and ouptput the column name, table name, data type, number of null values, and number of rows.
The problem that I run into is that when I run it, it runs for about two minutes, and then complains about an 'illegal use of LONG datatype', but I am not using any LONG here.
If I edit my search to only select WHERE rownum < 100 (commented out in the following code), it works perfectly. Additionally, if I only do the SELECT statement, it runs just fine and outputs all of the correct SQL statements. (about 18000 of them) So I am guessing that the error is in the loop somewhere.
Any guidance on how to fix this?
SET SERVEROUTPUT ON;
declare
myCol1 varchar2(1000);
myCol2 varchar2(1000);
myCol3 varchar2(1000);
myCol4 number;
myCol5 number;
begin
for line in
(
SELECT
'SELECT ''' || atc.column_name || ''', ''' || atc.table_name || ''', ''' || atc.data_type || ''',
SUM(CASE WHEN temp.'|| atc.column_name || ' IS NULL THEN 0 ELSE 1 END) "Filled Values",
COUNT(temp.' || atc.column_name || ') "Total Records"
FROM all_tab_columns atc
JOIN '|| atc.table_name || ' temp ON atc.column_name = ''' ||
atc.column_name ||''' AND atc.table_name = ''' || atc.table_name || '''' AS SQLRow
FROM all_tab_columns atc --WHERE rownum < 100
)
loop
execute immediate line.Sqlrow into myCol1, myCol2, myCol3, myCol4, myCol5;
INSERT INTO results VALUES (myCol1, myCol2, myCol3, myCol4, myCol5);
end loop;
end;
SELECT * FROM results;
/