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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值