NVL Syntax
-- DATE 데이터 타입
SQL> SELECT NVL(c2, '01/JAN/2011') as "Date" FROM NULL_T
2 WHERE c2 is null AND rownum <= 1 ;
Date
---------
01-JAN-11
SQL> ALTER SESSION SET nls_date_format = 'DD/MON/YYYY' ;
Session altered.
-- Charater 데이터 타입
SQL> SELECT NVL(c2, '01/JAN/2011') as "Date" FROM NULL_T
2 WHERE c2 is null AND rownum <= 1 ;
Date
-----------
01/JAN/2011
SQL> SELECT NVL(c3, 'Null Data') AS "Character" FROM NULL_T
2 WHERE c3 IS NULL AND ROWNUM <= 1 ;
Character
----------
Null Data
-- Number 데이터 타입
SQL> SELECT NVL(c3, 100) AS "Character" FROM NULL_T
2 WHERE c3 IS NULL AND ROWNUM <= 1 ;
Character
----------
100
SQL> SELECT NVL(c4, 'Null Data') AS "Number" FROM null_t
2 WHERE c4 IS NULL AND ROWNUM <= 1 ;
SELECT NVL(c4, 'Null Data') AS "Number" FROM null_t
*
ERROR at line 1:
ORA-01722: invalid number
SQL> SELECT NVL(c4, '10') AS "Number" FROM NULL_T
2 WHERE C4 IS NULL AND ROWNUM <= 1 ;
Number
----------
10
SQL> SELECT NVL(c4, 10) AS "Number" FROM NULL_T WHERE C4 IS NULL AND ROWNUM <= 1 ;
Number
----------
10
NVL2 Syntax
SQL> WITH null_t_temp AS ( SELECT c3
2 FROM NULL_T
3 WHERE c3 IS NULL AND ROWNUM <= 1
4 UNION ALL
5 SELECT c3
6 FROM NULL_T
7 WHERE c3 IS NOT NULL AND ROWNUM <= 1 )
8 SELECT c3, NVL2(c3, 'Not Null', 'Null') AS Return_Data
9 FROM null_t_temp ;
C3 RETURN_D
---------- --------
Null
01-APR-00 Not Null
SQL> WITH null_t_temp AS ( SELECT c3
2 FROM NULL_T
3 WHERE c3 IS NULL AND ROWNUM <= 1
4 UNION ALL
5 SELECT c3
6 FROM NULL_T
7 WHERE c3 IS NOT NULL AND ROWNUM <= 1 )
8 SELECT c3, NVL2(c3, 100, 100) AS Return_Data
9 FROM null_t_temp ;
C3 RETURN_DATA
---------- -----------
100
01-APR-00 100
SQL> WITH null_t_temp AS ( SELECT c3
2 FROM NULL_T
3 WHERE c3 IS NULL AND ROWNUM <= 1
4 UNION ALL
5 SELECT c3
6 FROM NULL_T
7 WHERE c3 IS NOT NULL AND ROWNUM <= 1 )
8 SELECT c3, NVL2(c3, 100, 'Null') AS Return_Data
9 FROM null_t_temp ;
SELECT c3, NVL2(c3, 100, 'Null') AS Return_Data
*
ERROR at line 8:
ORA-01722: invalid number
SQL> WITH null_t_temp AS ( SELECT c3
2 FROM NULL_T
3 WHERE c3 IS NULL AND ROWNUM <= 1
4 UNION ALL
5 SELECT c3
6 FROM NULL_T
7 WHERE c3 IS NOT NULL AND ROWNUM <= 1 )
8 SELECT c3, NVL2(c3, 100, '95') AS Return_Data
9 FROM null_t_temp ;
C3 RETURN_DATA
---------- -----------
95
01-APR-00 100
SQL> WITH null_t_temp AS ( SELECT c3
2 FROM NULL_T
3 WHERE c3 IS NULL AND ROWNUM <= 1
4 UNION ALL
5 SELECT c3
6 FROM NULL_T
7 WHERE c3 IS NOT NULL AND ROWNUM <= 1 )
8 SELECT c3, NVL2(c3, 'Not Null', 100) AS Return_Data
9 FROM null_t_temp ;
C3 RETURN_D
---------- --------
100
01-APR-00 Not Null
- 강좌 URL : http://www.gurubee.net/lecture/3804
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.