【问题标题】:IN , NOT IN for null value in oracleIN , NOT IN 用于 oracle 中的空值
【发布时间】:2018-06-22 05:57:53
【问题描述】:

在 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);

First Statement 将给出输出 = 2,6,8 第二条语句不会给出任何输出

谁能解释一下原因?

【问题讨论】:

标签: oracle notin


【解决方案1】:

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/

【讨论】:

    猜你喜欢
    • 2012-06-28
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2011-03-29
    相关资源
    最近更新 更多