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

 

 

 

 

posted @ 2011-08-03 16:30  饺子吃遍天  阅读(207)  评论(0编辑  收藏  举报