oracal中的null 与 ""
2016-04-27 11:54
169 查看
总结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:[b]在条件过滤中,oracal字段中如果值为“”或者null 不能通过= ,!= , <>, in() ,not in()等进行过滤,写条件过滤的时候应该特别注意!避免漏掉值为空的情况
[/b]
测试如下:
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' ;
验证如下:
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:[b]在条件过滤中,oracal字段中如果值为“”或者null 不能通过= ,!= , <>, in() ,not in()等进行过滤,写条件过滤的时候应该特别注意!避免漏掉值为空的情况
[/b]
测试如下:
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' ;
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- mysql 中存在null和空时创建唯一索引的方法
- C#中string.Empty和null的区别详解
- 基于不要返回null之EmptyFactory的应用详解
- 详解MySQL中的NULL值
- asp提示无效使用 Null: Replace
- sql 语句中的 NULL值
- JavaScript中为什么null==0为false而null大于=0为true(个人研究)
- JavaScript的null和undefined区别示例介绍
- 浅谈JavaScript中null和undefined
- JavaScript Undefined,Null类型和NaN值区别
- JS中判断null、undefined与NaN的方法
- MS Server和Oracle中对NULL处理的一些细节差异
- SQL中IS NOT NULL与!=NULL的区别
- 解析C语言中空指针、空指针常量、NULL & 0的详解
- SQL Server、Oracle和MySQL判断NULL的方法
- jquery获取下拉列表的值为null的解决方法
- 区分JS中的undefined,null,"",0和false
- JS基础之undefined与null的区别分析
- 理解Javascript_02_理解undefined和null