문방구앞오락기 2018. 2. 22. 18:19

NVL 함수는 NULL 값을 다른 값으로 바꿀 때 사용하며, 모든 데이터 타입에 적용이 가능하다. 

 

 

 

--NVL 

select empno, deptno, sal, NVL(Comm , 999) from emp 

order by deptno; 

이렇게 하면 null  999 바뀜 

 

 

--NVL2 

select empno, deptno, sal, NVL2(Comm , 111 , 999 ) from emp 

order by deptno; 

이건 안비어있으면 111 널이면 999 바꾸는 함수 

 

 

--COALESCE 이건 (조건1, 조건2, 조건3 ..) 계속 늘어나는형태 

 

 대해서 

 

select empno, deptno, sal, coalesce(comm, mgr, 111  ), mgr , comm from emp 

where deptno=10; 

 

이렇게 적으면 결과는 

 

 

처음에 comm 널이니깐 다음 mgr 가서 comm 널인부분이 mgr 값으로 채워지고 

Mgr null이니 다음 숫자 111 채워질부분이 채워진다.