在oracle中,为什么"Not in“不适用于空值,而" In”适用于例如
with temp(n,p) as (
select 1,2 from dual union all
select 3,2 from dual union all
select 4,6 from dual union all
select 5,6 from dual union all
select 2,8 from dual union all
select 6,8 from dual union all
select 8,null from dual
)
1. Select * from temp where n in (2,6,8,null);
2. Select * from temp where n not in (2,6,8,null);第一条语句将输出= 2,6,8第二条语句将不提供任何输出
有人能解释一下为什么吗?
发布于 2018-06-22 14:09:58
NOT IN本质上是这样工作的:
col NOT IN (value_a, value_b, value_c)
-- is the same as
col != value_a && col != value_b && col != value_c如果其中一个值为null,则整个表达式的计算结果为null,而不是true (这可能是您所期望的)。
你可以在这里阅读更多信息:https://jonathanlewis.wordpress.com/2007/02/25/not-in/
https://stackoverflow.com/questions/50981521
复制相似问题