
단순히 null체크를 위해 nvl, nvl2, coalesce를 사용하는 방법을 우린 알고 있다.
그러면 조건 연산자인 decode와 case에서 null을 처리하는 방법에는 무엇이 있는지에 대해 알아보고자 한다.
decode에서는 null체크를 반드시 null 키워드를 사용해서 체크해야 한다.
decode(입력 값, null, 참 값, 거짓 값)
SELECT
decode(commission_pct, null, (salary*12), (salary*12) + (salary*12*commission_pct))
FROM
hr.employees;
3번 째, 4번 째 인자의 입력 순서를 햇갈리지 말자.
case에서는 where절에서와 같이 is null 또는 is not null을 이용하 판단한다.
case when 조건문 is null then 참 값, 거짓 값
SELECT
case when commission_pct is null then (salary*12) else (salary*12) + (salary*12*commission_pct) endFROM
hr.employees;