본문 바로가기

Database/Oracle

특수 Query

-- CASE DECODE = SWITCH

--1번
SELECT employee_id, first_name, phone_number,
    CASE SUBSTR(phone_number, 1, 3)
        WHEN '515' THEN '서울'
        WHEN '590' THEN '부산'
        WHEN '659' THEN '광주'
        WHEN '603' THEN '대전'
        ELSE '기타'
    END AS "지역"
FROM employees;
--2번
SELECT employee_id, first_name, phone_number,
    CASE
        WHEN SUBSTR(phone_number,1,3) = '515' THEN '서울'
        WHEN SUBSTR(phone_number,1,3) = '590' THEN '부산'
        WHEN SUBSTR(phone_number,1,3) = '659' THEN '광주'
        WHEN SUBSTR(phone_number,1,3) = '603' THEN '대전'
        ELSE '기타'
    END AS "지역"
FROM employees;
--DECODE
SELECT employee_id, first_name, phone_number,
    DECODE( SUBSTR( phone_number,1,3),
        '515','서울',
        '590','부산',
        '659','광주',
        '603','대전',
        '기타')
FROM employees;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Database > Oracle' 카테고리의 다른 글

OVER(), PARTITION BY  (0) 2020.06.23
집합  (0) 2020.06.23
SUB Query  (0) 2020.06.23
헷깔린 문제~  (0) 2020.06.22
문자  (0) 2020.06.19