Oracle的in/not in(x,...,null)

简述

cola in (x,y,z)等价于 cola=x or cola=y or cola=z

cola not in (x,y,z)等价于 !(cola=x or cola=y or cola=z) 等价于 cola!=x and cola!=y and cola!=z

再说 cola=null和cola!=null,这两个表达式的结果都是false

然后就能看出来

cola in (x,y,...,z,null) 等价于 cola in (x,y,...,z)意思就是多你一个不多反正是 compareResult or false = compareResult,

cola not in (x,y,...z,null) 等价于 false 因为 compareResult and false = false,也就是把它放到where语句里面查不到任何记录。

参照地址http://x-spirit.iteye.com/blog/615603

今后我们在使用中记得,如果是用了select * from tablea where cola not in (select colb from tableb)这种子查询的时候,一定

要注意了,因为万一子查询里面有空值,那么就会查询不到结果。

原文地址:https://www.cnblogs.com/niutouzdq/p/4683399.html