728x90
반응형
예제 문제 :
-- emp 에서 comm 값이 null 인 경우는 '해당 없음'으로,
-- 아니면 원래 값이 출력되도록 empno,ename, sal, comm
-- 을 출력하라! (nvl,decode,case 사용)
select empno, ename, sal,
case
when comm is null then '해당없음'
when comm=0 then 'zero'
when comm>=300 and comm<=500 then 'sales'
else to_char(comm,'999,999') end
as 상여금
from emp;
Oracle SQLl 에서 case 문은
switch-case 문과 거의 비슷하다.
예제 문제 :
--job 이 'CLERK' 이면 sal*1.2 로 인상,
-- 'MANAGER' 면 sal*1.5로 인상하고
-- 나머지는 인상하지 않는다.
-- empno, ename, job, sal, 인상된 sal을 출력하라
--단, 소수점 첫째자리에서 반올림한다.
select empno, ename, job, sal,
case job
when 'CLERK' then trunc(sal*1.2)
when 'MANAGER' then trunc(sal*1.5)
else sal end as "인상된 sal"
from emp;
728x90
반응형
'기타 IT 지식 > SQL' 카테고리의 다른 글
[ Oracle ] Oracle Self Join 예제, 쓰는 이유 (0) | 2021.03.29 |
---|---|
[ Oracle ] Oracle CTAS 기법으로 테이블 복사하기 (0) | 2021.03.15 |
[ Oracle ] null 함수 (nvl 함수), decode 함수 (0) | 2021.03.15 |
[ Oracle ] 휴지통 확인하고 비우기 (0) | 2021.03.15 |
[ Oracle ] to_char를 이용해 숫자 사이의 컴마찍기 / 원화 출력하기 (0) | 2021.03.15 |