oracle中not in null 查询空值

在工作中执行以下SQL:

Select   *   from   table1 A  where  A.col1  not   in  (  select  col1  from  table2 B )

发现当B表中存在col1字段为空的数据时, 查询结果集是空。

在网上查询了一番,原来真的存在这个问题:

举例说明:     5 not in ('2','3','4',' ')   等价于 not (false or false or false or null)

=> not  null   即 查询不出结果集来。

所以如果非要用not in :

Select   *   from   table1 A  where  A.col1  not   in  (  select  col1  from  table2 B  where  B.col1  is   not   null  )

具体分析可以参考:

http://x-spirit.iteye.com/blog/615603

猜你喜欢

转载自121036081.iteye.com/blog/2191724