

Now it's not possible to know which columns have only NULL values before we run the query, but we can run a query to know which columns have only NULL values using an aggregate function like MAX, MIN OR SUM. SELECT 1,NULL, 2,NULL FROM DUAL UNION ALL

SELECT 1,NULL, NULL,3 FROM DUAL UNION ALL SELECT NULL,NULL, 1,3 FROM DUAL UNION ALL SELECT 1,CAST(NULL AS NUMBER), 2,4 FROM DUAL UNION ALL Lets create a sample table CREATE TABLE tab1 (c1, c2, c3, c4) AS Bear in mind that this means that every query has to run at least once before the query itself, which could be a downside if you're talking about large datasets. As explained above, that is not know at the time of running the query, but you could work around this, for example by creating a view that only has the columns with data. The requirement is to skip columns that have no data. The db engine does not know what is in those rows/columns.

At this point the database does not know anything about the results.
