以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
但是在符合的约束时 只有两个约束值都为空的时候才是不相等的,如果有一个值不为空 那么就是相当的。