Search code examples
sqloraclenullisnull

SQL to select only nulls from a table


I have a table with 260 columns, I just want to see only columns with nulls in it. I know there are a few longer versions to see that information but is there an quicker way ? Thanks Gurus


Solution

  • SELECT  t.column_name
    FROM    user_tab_columns t
    WHERE   t.nullable = 'Y' AND t.table_name = 'mytable' AND t.num_distinct = 0
    

    Also,before running it update your statistics:

    BEGIN
    DBMS_STATS.gather_database_stats();
    END