您的位置:首页 > 数据库 > Oracle

oracle中not in(null)问题

2014-09-19 14:14 176 查看
如下sql语句

select aid from A where bid not in(select bid from B where bname='')

如果bname的记录在数据库中没有 就相当于 in(null) 此时 not in(null) 按理是要查询所有的A表中的记录

事实确实一条都没查出来

可以用以下语句测试以下

select aid from A where bid not in(null)

其实就是因为 相当于 bid!=null 这样是没有记录查询出来的

如果用 bid is null就能查询出来

可以修改sql语句未

select aid from A where bid not in(select nvl(bid,'-1') from B where bname='')

这样不会出现空的结果 将-1当作空来使用 前提是bid中不能出现 -1的结果 不然就不行了

-1的值视情况而定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: