如果你需要知道什么IN
子句中列出的项目没有在表中找到匹配,你可以采取用户的优势定义的或内置的集合 - 嵌套表或变量数组。下面的示例使用内置集合sys.odcinumberlist()
元素就是数数据类型:
/*sample of data */
with t1(col) as(
select level
from dual
connect by level <= 11
)
select s.column_value as missing_val
from t1 /* here you list the elements as you would using IN clause*/
right join table(sys.odcinumberlist(1,2,3,4,5,6,7,8,9,10, 70)) s
on (t1.col = s.column_value)
where t1.col is null
结果:
MISSING_VAL
------------
70
如果你的列表中的元素是varchar
数据类型,则OdciVarchar2List()
集合可以是对date
数据类型的元素使用或ODCIDateList()
。您还可以自由创建自己的SQL类型集合。例如:
create or replace type T_Type_Name is table of number
使用'NOT IN(..)'... –