oracle中not in(null)问题

如下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的值视情况而定

原文地址:https://www.cnblogs.com/liaomin416100569/p/9331482.html