首页 > 其他 > 详细

about null-from cyber

时间:2015-12-28 18:29:37      阅读:202      评论:0      收藏:0      [点我收藏+]

SQLPLUS

1.
SQL> select 1 from dual where null=null;
未选定行

SQL> select 1 from dual where null=‘‘;
未选定行

SQL> select 1 from dual where null=0;
未选定行

SQL> select 1 from dual where ‘‘=‘‘;
未选定行

以上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是不会违反唯一行约束的。

about null-from cyber

原文:http://www.cnblogs.com/Jeffrey-xu/p/5083342.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!