환경
윈도우10 64비트
오라클 18c 익스프레스
스캇 예제
예제를 확인하시려면
https://ondolroom.tistory.com/163
DECODE
SELECT DECODE(조건값, 비교할갌, 참일경우 출력, 거짓일 경우 출력)
FROM DUAL;
-- DECODE = IF문과 같이 사용, 인수는(조건변수, 비교할변수, 참일경우, 거짓일경우)
SELECT DECODE('LOVE', 'LOVE','참', '거짓')
FROM DUAL;
SELECT deptno, name, DECODE(deptno, 101, 'Computer Engineering', ' ')
FROM professor;
SELECT deptno, name, DECODE(deptno, 101, 'Computer Engineering', 'ETC')
FROM professor;
SELECT deptno, name, DECODE(조건값, 비교할값1, 비교할값1 일 경우 출력,
비교할값2, 비교할값2 일 경우 출력,
비교할값3, 비교할값3 일 경우 출력,
비교할 값이 모두 아닐경우) "열 이름"
FROM professor;
SELECT deptno, name, DECODE(deptno, 101, 'Computer Engineering',
102, 'Multimidia Engineering',
103, 'Software Engineering',
'ETC') "DNAME"
FROM professor;
SELECT deptno, name, DECODE(조건값, 비교할값, DECODE(조건값2, 비교할값2, 참일경우 출력2, 거짓일 경우 출력2), 거짓일 경우 출력) "BEST"
FROM professor;
SELECT deptno, name, DECODE(deptno, 101, DECODE(name, '조인형', 'BEST!', ' '), ' ') "BEST"
FROM professor;
SELECT deptno, name, DECODE(deptno, 101, DECODE(name, '조인형', 'BEST!', 'GOOD!'), ' ') "BEST"
FROM professor;
SELECT deptno, name, DECODE(deptno, 101, DECODE(name, '조인형', 'BEST!', 'GOOD!'), 'N/A') "BEST"
FROM professor;
SELECT name, jumin, DECODE(SUBSTR(jumin, 7,1), '1','MAN','2', 'WOMAN') "Gender"
FROM student
WHERE deptno1 = 101;
SELECT name, tel, DECODE(SUBSTR(tel, 1, INSTR(tel,')')-1), '02', 'SEOUL',
'031', 'GYEONGGI',
'051', 'BUSAN',
'052', 'ULSAN',
'055', 'GYEONGNAM') "LOC"
FROM student
WHERE deptno1 = 101;
'Database > OracleSQL' 카테고리의 다른 글
오라클 SELECT , FROM, WHERE 문제 (0) | 2020.03.25 |
---|---|
오라클 명령어 실행순서 (0) | 2020.03.25 |
오라클 현재 날짜 출력 + 시간 (0) | 2020.03.25 |
오라클 POWER, ROUND, MOD (0) | 2020.03.25 |
오라클 오름차순 내림차순 ORDER BY (0) | 2020.03.25 |