博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

not in(有空值的子查询) 为什么返回空值

Posted on 2017-04-17 21:52  那家店  阅读(1071)  评论(0)    收藏  举报

 

SQL> select * from dual where 'a' not in ('b', null);
未选定行

not in 相当于 !=
SQL> select * from dual where 'a' != 'b' and 'a' != null;

 

有null参与的运算:

  • null参与算术运算,则该算术表达式的值为null
  • null参与比较运算,则结果可视为false
  • 聚集函数会忽略null(count(*)除外)

所以在not in子查询中有null值的时候,则不会返回数据。