Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Count not null values in each column in a database

MarwimMar 3 2010 — edited Mar 3 2010
Hello,

I need to write a routine that counts how many not null values each column in a database has.
The first idea might be to loop over all_tables / all_tab_cols and write a select like
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM '||table_name||' WHERE '||column_name||' IS NOT NULL' INTO v_count;
Yet this would mean a full table scan for every non indexed column. That's pretty much when I have a maximum of 59 columns for one table and millions of rows.

Any better idea? I don't need the exact count. E.g. for the number of rows in a table I simply use all_tables.num_rows.

Regards
Marcus
This post has been answered by MichaelS on Mar 3 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2010
Added on Mar 3 2010
5 comments
4,838 views