1) NVL
It accepts exactly two arguments. If the first argument is null then display the second argument else display the first argument.
Example
SELECT NVL(COMMISSION_PCT,0)FROM EMPLOYEES;
2) NVL2
It accepts exactly three arguments. If the first argument is null then display the third argument else display the second argument.
Example
It accepts exactly two arguments. Display null if both the arguments are same else display the first argument
Example
SQL> SELECT empno,sal FROM EMP;
EMPNO SAL
---------- ----------
8457 45000
7369 8800
7902 17800
7546 8600
7499 9565
SQL> SELECT EMPNO, NULLIF(SAL,8800) FROM EMP;
EMPNO NULLIF(SAL,8800)
---------- ----------------
8457 45000
7369
7902 17800
7546 8600
7499 9565
4) COALESCE
It can contain two or more number of arguments and it returns the first not null from the arguments list.
Example
SELECT COALESCE(COMMISSION_PCT,SALARY) FROM EMPLOYEES;
It accepts exactly two arguments. If the first argument is null then display the second argument else display the first argument.
Example
SELECT NVL(COMMISSION_PCT,0)FROM EMPLOYEES;
2) NVL2
It accepts exactly three arguments. If the first argument is null then display the third argument else display the second argument.
Example
SQL> select empno, NVL2(COMM,2,1) FROM EMP;
EMPNO COMM
---------- --------------
8457 2
7369 2
7902 2
7546 1
7499 2
7839 2
7844 2
7900 2
7029 2
7019 1
7845 2
7901 2
SQL> select empno, NVL2(COMM,2,1) FROM EMP;
EMPNO COMM
---------- --------------
8457 2
7369 2
7902 2
7546 1
7499 2
7839 2
7844 2
7900 2
7029 2
7019 1
7845 2
7901 2
3) NULLIF
It accepts exactly two arguments. Display null if both the arguments are same else display the first argument
Example
SQL> SELECT empno,sal FROM EMP;
EMPNO SAL
---------- ----------
8457 45000
7369 8800
7902 17800
7546 8600
7499 9565
SQL> SELECT EMPNO, NULLIF(SAL,8800) FROM EMP;
EMPNO NULLIF(SAL,8800)
---------- ----------------
8457 45000
7369
7902 17800
7546 8600
7499 9565
4) COALESCE
It can contain two or more number of arguments and it returns the first not null from the arguments list.
Example
SELECT COALESCE(COMMISSION_PCT,SALARY) FROM EMPLOYEES;
No comments:
Post a Comment