Oracle SQL:从IN子句检索不存在的值 [英] Oracle SQL : Retrieving non-existing values from IN clause
本文介绍了Oracle SQL:从IN子句检索不存在的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具有以下查询:
select table_name
from user_tables
where table_name in ('A','B','C','D','E','F');
假设仅存在user_tables记录B,C和F,我想检索不存在的值A,D和E.这是一个简单的示例,在现实世界中,列表可能很大.
Assuming only user_tables records B,C, and F exist, I want to retrieve the non-existing values A,D and E. This is a simple example, on real world the list can be huge.
推荐答案
生成伪造行的一种好方法是使用标准集合,例如sys.odcivarchar2list
:
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
这篇关于Oracle SQL:从IN子句检索不存在的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文