日期:2014-05-17  浏览次数:21109 次

oracle 查询空值问题
在A表中 查询 a、b、c三个字段
条件为 
a='1' 或者 a is null 
b='2' 或者 b is null 
c='3' 或者 c is null 

以上条件都要满足
select a,b,c
from A 
where a in (1,null)
and  b in (2,null)
and c in (3,null)
 这样写法是错的。。但不知道正确怎么写
------解决方案--------------------

select a,b,c
from A 
where (a='1' or a is null) and (b=2 or b is null) and (c='3' or c is null)


------解决方案--------------------
引用:
我的是Oracle 11g
搂主那么写,没抱错。。。。

这么写。。也没抱错。。还查出来了数据




SQL code
?



123456

select a,b,c from A  where a in ('1','') and  b in ('2','') and c in ('3','')


错的哦,  你差出的数据时那个不是NULL的。 NULL的是查不出来的  1楼的做法是正确的

------解决方案--------------------
你们是不是弄复杂了。。
select a,b,c
from A 
where nvl(a, '1') = '1' and nvl(b, '1') = '1' and nvl(b, '1') = '1'

------解决方案--------------------
NULL这个是不能放IN里的,有专用函数NVL,5L正解