oracle is null 和is not null
来源:互联网 发布:怎么找淘宝客服 编辑:程序博客网 时间:2024/05/21 16:57
当字符串为空时,在where 使用 is null来判断。
例如:
create table test
(
stuno number(10) primary key,
stuname varchar2(50)
)
insert into test(stuno) values(10)
insert into test(stuno,stuname) values(11,' ')
select * from test where stuname is null才会取到所有值。
而select * from test where stuname=''不行。
oracle中的null处理的简单理解
首先对oracle中的null做一些简单的说明:
1、oracle中null与0,空字符串,空格,包括null与null也是不等的。
2、oracle中对null做算术运算结果仍然为null。
3、处理方法有nvl函数,比较方法是is null或者is not null。
4、null不能被索引,比如select count(null) from dual的查询结果是0。
5、null排序比其他所有类型的大,一个可以为空的字段倒排序,前面的都是null数据。
下面举例说明:
1、
SQL> select 1 from dual where null=null; false
未选定行
SQL> select 1 from dual where null=''; false
未选定行
SQL> select 1 from dual where null=0; false
未选定行
SQL> select 1 from dual where ''=''; false
未选定行
以上4个查询中,大家可以看到null在oracle中可以理解为什么都没有的意思,它与任何对象都是不相等的。
2、
SQL> select 1+null from dual;
1+NULL
----------
SQL> select 1-null from dual;
1-NULL
----------
SQL> select 1*null from dual;
1*NULL
----------
SQL> select 1/null from dual;
1/NULL
---------
-
SQL> select 1 from dual where 1+null is null;
1
----------
1
SQL> select 1 from dual where 1-null is null;
1
----------
1
SQL> select 1 from dual where 1*null is null;
1
----------
1
SQL> select 1 from dual where 1/null is null;
1
----------
1
以上是null的加减乘除操作,可见null的加减乘除是null。
3、
SQL> select 1 from dual where null is null;
1
----------
1
SQL> select 1 from dual where '' is null;
1
----------
1
SQL> select 1 from dual where nvl(null,0) is not null;
1
----------
1
以上两个查询可以看出null的判断方法是is null,nvl是对null做处理的函数;而且,空字符串也被认为是null。
提示:null是不能被%匹配到的如select 1 from dual where null like '%'是查不到结果的。
4、
SQL> select count(null) from dual;
COUNT(NULL)
-----------
0
SQL> select count(nvl(null, 0)) from dual;
COUNT(NVL(NULL,0))
------------------
1
以上两个查询提醒大家在统计的时候注意根据自己的需要处理null字段的问题。
其他说明:
根据oracle中null的定义,null为未知,不等于null,因此在表中的唯一字段中存在多个null是不会违反唯一行约束的。
- oracle is null 和is not null
- is null 和 is not null
- is null && is not null
- oracle 性能优化操作六: 去掉Where子句中的IS NULL和IS NOT NULL
- oracle 性能优化操作六: 去掉Where子句中的IS NULL和IS NOT NULL
- ORACLE查询优化之is null和is not null优化
- hive中使用is null和is not null问题
- is null 和 is not null 都不能利用 索引
- hive中使用is null和is not null问题
- mysql查询语句select-(null,not null,is null和is not null)
- mysql查询语句select-(null,not null,is null和is not null)
- ORACLE-017:SQL优化-is not null和nvl
- mysql <> null != null is not null
- Oracle之NULL IS NULL
- "=NULL"和"Is NULL"
- not in和select ** from is null
- Oracle IS NULL
- ORACLE的is null和=null的区别
- 六、理解 数据类型
- 在未安装Flash播放器的电脑上C#开发Flash播放器时遇到到问题
- 转载和积累系列 - 淘宝tddl系统
- 七、基本数据类型-整数类型
- POI概述及简单举例
- oracle is null 和is not null
- Silverlight开源项目与第三方控件收集
- cxf开发并调用webservice
- 八、整数值的 大小 和 范围
- USACO 1.4 ariprog
- Oracle 坏块总结
- 九、基本数据类型-浮点类型
- Swing文本输入
- Javascript中对象继承方式详解