Select only Columns without Null values in Oracle

后端 未结 2 1013
离开以前
离开以前 2020-12-22 03:10

I have 20 columns in my table....

How can I select only columns that don\'t have null value

col1 col2 col3
20    12   null

Desired

相关标签:
2条回答
  • 2020-12-22 03:32

    The semantics of SQL don't allow this - every SQL query includes a projection, by which you specify what columns you want in the output.

    Unless you run the query twice, you can't know ahead of time what the results will be. In fact, even if you run the query twice, the results may change in between (unless you run it in serializable mode).

    In other words, the question doesn't make a lot of sense.

    On the other hand, if your requirement is to simply hide the column when displayed to the user, that's an entirely different question - one for which the answer does not lie in SQL, but in your presentation logic.

    0 讨论(0)
  • 2020-12-22 03:37

    You can go to the table's metadata and check for the columns which are defined NOT NULL and create a select query with only those columns.

    0 讨论(0)
提交回复
热议问题