oracal中的null 与 ""

总结1:oracal中认为null 与 "" 是相同的。

验证如下:

select (case when '' is null then 'true' else 'false' end) as result from dual;  --true

select (case when trim('      ') is not null then 'not null' else 'is null' end) as age from dual;  --true

select (case when ('   ') is not null then 'not null' else 'is null' end) as age from dual; --false


总结2:在条件过滤中,oracal字段中如果值为“”或者null 不能通过= ,!= , <>,  in()  ,not in()等进行过滤,写条件过滤的时候应该特别注意!避免漏掉值为空的情况

测试如下:

select (case when ''=''  then 'true' else 'false' end) as result from dual;--false

select (case when '' !='01' then 'true' else 'false' end) as result from dual;--false

select (case when '' <>'01' then 'true' else 'false' end) as result from dual;--false

select (case when '' in('',null) then 'true' else 'false' end) as result from dual;--false
select (case when null in('',null) then 'true' else 'false' end) as result from dual;--false

select (case when ''  not in('01') then 'true' else 'false' end) as result from dual;--false

例如

user 表中有三条记录

userid  usename

1             u1

2            

3             u3

查询用户名不是u1的数据

select  *  from  user  u  where u.username  <> 'u1' ;-- 这样讲只返回第三条,第二条没有在查询范围内。

正确写法:

select  *  from  user  u  where u.username is null or  u.username  <> 'u1' ;





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值