关于NVL函数用途学习的一些技术

以oracle 自带的scott 用户下的emp位列子

在统计有多少的人的comm不为空时

首先想到的是 使用count() 函数 其实也可以使用nvl函数来实现:sum(nvl2(comm,1,0));

这里只是提供了一种思路和 执行效率没有关系。

 

数据中有null值进行排序的时候 nll值并不是无限大的,这种说法是错误的可以在order by table1.column后+nulls last/first 来控制 null值的排序

 

在 子查询中,如果必须保证要控制 所需结果集的值不为空!!!

select ename,comm
from emp
where comm not in
(select comm
from emp
where ename='ALLEN' or ename='SCOTT');

是错误的

正确的是:

select ename .comm

from emp

where comm not in

(select nvl(comm,-1) from

emp where ename='' or ename=''):

或者是:

select ename .comm

from emp

where comm not in

(select comm from

emp where comm is not null and(ename='' or ename='')):

 

在使用聚集函数如 unionall merger,等函数是 null=null

 

在使用符合唯一约束时 null=null

但是在符合的约束时 只有两个约束值都为空的时候才是不相等的,如果有一个值不为空 那么就是相当的。

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值