码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-07-28 17:28:23      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

简述

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)这种子查询的时候,一定

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

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!