Search code examples
oracle-databaseoracle11goracle10gconstraintsnotnull

How to get all not null columns in a table


I have a requirement to find all not-null columns in a table. For example, my table is the below one

enter image description here

Lets say, Column1, Column2 and Column3 have not-null constraints and Column4, Column5 and Column6 are of nullable types. Is there any query in Oracle that list the column names that are of not-null types, ie I need to get the column names Column1, Column2 and Column3.

DESIRED OUTPUT

Column1
Column2
Column3

I know there should be a simple way to achieve this, but am new to Oracle. Any help would be highly appreciated.


Solution

  • You can query the all_tab_columns table:

    select column_name
    from all_tab_columns
    where table_name = 'TABLE1'
    and nullable = 'N';