Oracle SQL : Retrieving non-existing values from IN clause

前端 未结 5 1481
孤独总比滥情好
孤独总比滥情好 2021-01-23 16:00

Having following query:

select table_name
from user_tables
where table_name in (\'A\',\'B\',\'C\',\'D\',\'E\',\'F\');

Assuming only user_tables

5条回答
  •  悲&欢浪女
    2021-01-23 16:47

    A good way to generate fake rows is with a standard collection such as sys.odcivarchar2list:

    select
        tables_to_check.table_name,
        case when user_tables.table_name is null then 'No' else 'Yes'end table_exists
    from
    (
        select column_value table_name
        from table(sys.odcivarchar2list('does not exist', 'TEST1'))
    ) tables_to_check
    left join user_tables
        on tables_to_check.table_name = user_tables.table_name
    order by tables_to_check.table_name;
    
    
    TABLE_NAME       TABLE_EXISTS
    ----------       ------------
    TEST1            Yes
    does not exist   No
    

提交回复
热议问题