null相关函数

1. nvl(expr1,expr2) 如果expr为空则返回expr2。如果expr2为表达式的话,不论expr1是否为空,expr2总是会执行,coalesce不会

select nvl(e.commission_pct,11) from employees e;--如果奖金为空,则返回11

 

2. nvl2(expr1,expr2,expr3) 如果expr1不为空返回expr2,否则返回expr3

select nvl2(e.commission_pct, e.commission_pct + 1, 11)
  from employees e --如果工资不为空则+1,为空返回11

 

3. lnnvl(expr) 如果expr为false,或者expr内进行判断的字段为空则返回true

  select * from employees e
  where lnnvl(e.commission_pct > 0.2); --查询奖金为空和奖金不大于0.2的员工信息

 

4. nanvl(n1,n2)

 

5.nullif(expr1,expr2) 如果expr1等于expr2则返回null,否则返回expr1

   select nullif('a', 'a'), nullif('a', 'b') from dual; --查询结果为空和a

 

6. coalesce(expr1,expr2...) 返回第一个非空表达式的值,至少要有两个参数,如果未查询到非空数据返回空

select coalesce(null, null, null, 14, null), coalesce(null, null, null)
     from dual; --查询结果为14和空

 

posted on 2016-02-15 21:38  收苞米的拖拉机  阅读(194)  评论(0)    收藏  举报