about null-from cyber

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

转载于:https://www.cnblogs.com/Jeffrey-xu/p/5083342.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值