case절과 decode절의 문법차이
SELECT empno
, ename
, sal
, CASE job WHEN 'SALESMAN' THEN 1.10 * sal
WHEN 'PRESIDENT' THEN 1.15 * sal
WHEN 'MANAGER' THEN 1.20 * sal
ELSE sal
END revised_sal
FROM EMP
;
SELECT empno
, ename
, sal
, DECODE(job, 'SALESMAN', 1.10 * sal
, 'PRESIDENT', 1.15 * sal
, 'MANAGER', 1.20 * sal
, sal) revised_sal
FROM EMP
;
ex>
,DECODE(C.SE_RST_SCD,'420','','431','',SUBSTR(C.SE_RST_SCD,1,3)) RTT_CUS_SCD /* 리텐션회원상태코드 */
,CASE WHEN (SELECT MAX('Y')
FROM CSLSA0001 /* A.매출_매출전표 */
WHERE BG_CZ_BSN_PD_CD = '1' /* 대분류영업상품코드 */
AND CLN_DFR_N = A.CLN_DFR_N
AND LSP_RID BETWEEN CASE WHEN SUBSTR(:EDD,7,2) < '05'
THEN TO_CHAR(ADD_MONTHS( TO_DATE(:EDD,'YYYYMMDD'),-2), 'YYYYMM') || '01'
ELSE TO_CHAR(ADD_MONTHS( TO_DATE(:EDD,'YYYYMMDD'),-1), 'YYYYMM') || '01'
END
AND :EDD
AND SAA > 0) = 'Y'
THEN 'Y'
WHEN (SELECT MAX('Y')
FROM CSLSA0001 /* A.매출_매출전표 */
WHERE BG_CZ_BSN_PD_CD = '2' /* 대분류영업상품코드 */
AND CLN_DFR_N = A.CLN_DFR_N
AND LSP_RID BETWEEN CASE WHEN SUBSTR(:EDD,7,2) < '05'
THEN TO_CHAR(ADD_MONTHS( TO_DATE(:EDD,'YYYYMMDD'),-2), 'YYYYMM') || '01'
ELSE TO_CHAR(ADD_MONTHS( TO_DATE(:EDD,'YYYYMMDD'),-1), 'YYYYMM') || '01'
END
AND :EDD
AND SAA > 0) = 'Y'
THEN 'Y'
WHEN (SELECT MAX('Y')
FROM CSLSA0001 /* A.매출_매출전표 */
WHERE BG_CZ_BSN_PD_CD = '3' /* 대분류영업상품코드 */
AND CLN_DFR_N = A.CLN_DFR_N
AND LSP_RID BETWEEN CASE WHEN SUBSTR(:EDD,7,2) < '05'
THEN TO_CHAR(ADD_MONTHS( TO_DATE(:EDD,'YYYYMMDD'),-2), 'YYYYMM') || '01'
ELSE TO_CHAR(ADD_MONTHS( TO_DATE(:EDD,'YYYYMMDD'),-1), 'YYYYMM') || '01'
END
AND :EDD
AND SAA > 0) = 'Y'
THEN 'Y'
ELSE 'N'
END SLS_UE_F /* 매출이용여부 */
,CASE WHEN A.CRD_NS_F <> 'Y' AND SUBSTR(A.CSL_CD,1,4) BETWEEN '7400' AND '7499'
THEN 'Y'
ELSE 'N'
END CSL_SUS_F /* 상담성공여부 */
'Oracle' 카테고리의 다른 글
alter : 테이블 변경 (0) | 2013.02.14 |
---|---|
테이블 복제와 데이터 삽입 (0) | 2013.02.13 |
NVL 관련 (0) | 2013.02.13 |
month 관련 함수 (0) | 2013.02.13 |
show all : set : linux 쿼리 뷰 세팅 (0) | 2013.02.13 |