NVL and NVL2 Difference

NVL and NVL2 Difference


--====================================================
-- Table Structure and data
--====================================================

select * from XX_EMP


EMPNO
ENAME
JOB
MGR
SAL
COMM
DEPTNO
7369
SMITH
CLERK
7902
800

20
7499
ALLEN
SALESMAN
7698
1600
300
30
7521
WARD
SALESMAN
7698
1250
500
30
7566
JONES
MANAGER
7839


20
7654
MARTIN
SALESMAN
7698
1250
1400
30
7698
BLAKE
MANAGER
7839
2850

30
7782
CLARK
MANAGER
7839
2450

10
7788
SCOTT
ANALYST
7566


20
7839
KING
PRESIDENT

5000

10
7844
TURNER
SALESMAN
7698
1500
10
30
7876
ADAMS
CLERK
7788
1100

20
7900
JAMES
CLERK
7698
950

30
7902
FORD

7566
3000

20
7934
MILLER
CLERK
7782
1300

10


--====================================================
-- NVL 
--====================================================

select ENAME, NVL(JOB,'DEVELOPER' )NEW_JOB, JOB from XX_EMP A

ENAME
NEW_JOB
JOB
SMITH
CLERK
CLERK
ALLEN
SALESMAN
SALESMAN
WARD
SALESMAN
SALESMAN
JONES
MANAGER
MANAGER
MARTIN
SALESMAN
SALESMAN
BLAKE
MANAGER
MANAGER
CLARK
MANAGER
MANAGER
SCOTT
ANALYST
ANALYST
KING
PRESIDENT
PRESIDENT
TURNER
SALESMAN
SALESMAN
ADAMS
CLERK
CLERK
JAMES
CLERK
CLERK
FORD
DEVELOPER

MILLER
CLERK
CLERK

select ENAME, SAL ,
(SAL*10)/100 REMB,
NVL(SAL, 1000 ) NEW_SAL,
( NVL(SAL,1000)*10)/100NEW_REMB
from XX_EMP A


ENAME
SAL
REMB
NEW_SAL
NEW_REMB
SMITH
800
80
800
80
ALLEN
1600
160
1600
160
WARD
1250
125
1250
125
JONES


1000
100
MARTIN
1250
125
1250
125
BLAKE
2850
285
2850
285
CLARK
2450
245
2450
245
SCOTT


1000
100
KING
5000
500
5000
500
TURNER
1500
150
1500
150
ADAMS
1100
110
1100
110
JAMES
950
95
950
95
FORD
3000
300
3000
300
MILLER
1300
130
1300
130

--====================================================
--NVL2
--====================================================

select ENAME, COMM, NVL2(COMM, 100, 250) NEW_COMM  ,
JOB, NVL2(JOB, 'DEVELOPER', 'FRESHER') NEW_JOB
from XX_EMP A

ENAME
COMM
NEW_COMM
JOB
NEW_JOB
SMITH

250
CLERK
DEVELOPER
ALLEN
300
100
SALESMAN
DEVELOPER
WARD
500
100
SALESMAN
DEVELOPER
JONES

250
MANAGER
DEVELOPER
MARTIN
1400
100
SALESMAN
DEVELOPER
BLAKE

250
MANAGER
DEVELOPER
CLARK

250
MANAGER
DEVELOPER
SCOTT

250
ANALYST
DEVELOPER
KING

250
PRESIDENT
DEVELOPER
TURNER
10
100
SALESMAN
DEVELOPER
ADAMS

250
CLERK
DEVELOPER
JAMES

250
CLERK
DEVELOPER
FORD

250

FRESHER
MILLER

250
CLERK
DEVELOPER


Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor