I have really big Oracle table with many columns that are not relevant to each filter that I use.
I want to write a query or function in Oracle that returns the name of the columns that have only null values or alternatively the name of the columns which are not null.
If you just want to find the columns that are always null you can run the query that this query creates, those columns that have a value 0 are null.
Here’s a SQL Fiddle to demonstrate.
If you want the names of the columns you have to use PL/SQL. This function will return a comma delimited list of column names, but of course you could return a user defined type etc.
Here’s an extension to the same SQL Fiddle with the function added.
I have to just add that if you’re accepting user input in order to use the function you should use the
dbms_assertpackage in order to help avoid SQL Injection.