How to identify Columns having all NULL values?
SET SERVEROUTPUT ON;
DECLARE
l_count number;
BEGIN
For col in (Select TABLE_NAME, COLUMN_NAME From USER_TAB_COLUMNS Where TABLE_NAME= :TABLENAME)
Loop
Execute Immediate 'Select Count(*) From ' ||col.TABLE_NAME|| ' Where ' ||col.COLUMN_NAME || ' IS NOT NULL ' into l_count;
If l_count=0 Then
DBMS_OUTPUT.PUT_LINE( 'Column :' ||col.COLUMN_NAME|| ' contains all NULL Records');
Else
DBMS_OUTPUT.PUT_LINE( 'Column :' ||col.COLUMN_NAME|| ' contains ' ||l_count|| ' NOT NULL Records');
End IF;
End Loop;
END;
#GoLearningPoint
For Interview questions and other topics -
https://tipsfororacle.blogspot.com/