NVL( string1, replace_with)
功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值
通俗的说,就是给string创建默认值。如果string不为0,则是其本身,如果其为空,则赋值为replace_with
例如:select nvl(comm,0) from emp; 查出来的数据,没有奖金的人,自动显示奖金为0,而不是空。
NVL2(E1, E2, E3)的功能为:如果E1为NULL,则函数返回E3,若E1不为null,则返回E2。
例如:select empno, ename,sal,comm, nvl2(comm,sal+comm, sal) total from emp;
如果有奖金,即comm不为空,就计算sal+comm,反之,就只计算sal,算出total