Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

query to identify NULL and NOT NULL columns

1932140Apr 16 2018 — edited Apr 17 2018

Hi

I have the following query:

select uc.table_name

      ,uc.column_name

      ,ucc.constraint_name

      ,uco.search_condition

      ,uc.column_id

from   user_tab_columns  uc

left outer join user_cons_columns ucc on (   uc.table_name  = ucc.table_name

                                         and uc.column_name = ucc.column_name)

left outer join user_constraints  uco on (ucc.constraint_name = uco.constraint_name)

where  uc.table_name = '&&TABLE_NAME'

and  ( uco.constraint_type = 'C' or uco.constraint_type is NOT null)

and 'N' = '&&IS_NULL'

union all

select uc.table_name

      ,uc.column_name

      ,ucc.constraint_name

      ,uco.search_condition

      ,uc.column_id

from   user_tab_columns  uc

left outer join user_cons_columns ucc on (   uc.table_name  = ucc.table_name

                                         and uc.column_name = ucc.column_name)

left outer join user_constraints  uco on (ucc.constraint_name = uco.constraint_name)

where  uc.table_name = '&&TABLE_NAME'

and  ( uco.constraint_type = 'C' or uco.constraint_type is null)

and 'Y' = '&&IS_NULL'

order by column_id;

When I specify "N" for the IS_NULL parameter, then the correct rows appear, but when specifying "Y", then both NULL and NOT null columns appear.

Is there a way I can get only one list or the other ?

for example, for the following table:

CREATE GLOBAL TEMPORARY TABLE TBL_GT (ID INTEGER, X VARCHAR2(10) NOT NULL);

I would like to see only the columns ID if "Y" is specified and only the column X if "N" is specified.

This post has been answered by BEDE on Apr 16 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2018
Added on Apr 16 2018
15 comments
4,372 views