(转)not in(1,2..) ,null 查不出来的问题

今天同事遇到一个问题:

select    'true '   from   dual   where   (1,2)   not   in   ((2,3),(2,null)); 

select 'true ' from dual where (2,1) not in ((2,3),(2,null)); 

以上两个例子的结果居然不同
 
 
in/not   in在判断NULL时用的与=/ <> 一样的方式,即必须用is   null来判断,否则始终为失败。 
语句 
select   'true '   from   dual   where   (1,2)   not   in   ((2,3),(2,null)); 
成功的原因在于判断二元值时首先判断其中一个非null元素,该元素成功或者失败会“短路”另一个个。由于上述第一个元素就使not   in成功了,因此第二个元素就不再处理。 
语句 
select   'true '   from   dual   where   (2,1)   not   in   ((2,3),(2,null)); 
的第一个元素没有造成“短路”,因此引起了null判断,从而结果始终为失败。 
请再实验语句 
select   'true '   from   dual   where   (2,1)   not   in   ((2,3),(null,3)); 
其结果为true,原因是第二个元素短路了第一个元素。 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
select a.InsuredAddressCountry, a.insuredaddressstate, a.insuredaddresscity, a.insuredaddressdistrict, a.policyno, c.countrycode as 国家, c.regioncode as 省, c.area as 市, c.clientdistrict 区县, a.endorseqno, a.insuredcode, a.insuredtype from guPolicyCopyRelatedParty a, GSClientCorporate c where (((a.insuredaddresscity is not null and a.insuredaddressstate is not null and (select b.upperareacode from ggcountry b where b.countrycode = a.insuredaddresscity and b.arealevel = '3' and b.upperareacode = a.insuredaddressstate) is null) or (a.insuredaddressstate is not null and a.insuredaddresscountry is not null and (select b.upperareacode from ggcountry b where b.countrycode = a.insuredaddressstate and b.arealevel = '2' and b.upperareacode = a.insuredaddresscountry) is null) or (a.insuredaddressdistrict is not null and a.insuredaddresscity is not null and (select b.upperareacode from ggcountry b where b.arealevel = '4' and b.countrycode = a.insuredaddressdistrict and b.upperareacode = a.insuredaddresscity) is null)) or (a.insuredaddresscountry is null and (a.insuredaddressstate is not null or a.insuredaddresscity is not null or a.insuredaddressdistrict is not null)) or (a.insuredaddresscity is not null and a.insuredaddressstate is null) or (a.insuredaddressdistrict is not null and (a.insuredaddressstate is null or a.insuredaddresscity is null))) and a.insuredtype in ('2', '4') and a.insuredcode = c.clientcode order by a.insuredaddresscountry,a.insuredaddressstate,a.insuredaddresscity,a.insuredaddressdistrict; 此sql如何根据where后的条件进行判断给自定义的返回结果赋值
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值