SELECT
CASE WHEN (LEVEL*7-6-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-6-WEEK) END AS 일
,CASE WHEN (LEVEL*7-5-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-5-WEEK) END AS 월
,CASE WHEN (LEVEL*7-4-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-4-WEEK) END AS 화
,CASE WHEN (LEVEL*7-3-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-3-WEEK) END AS 수
,CASE WHEN (LEVEL*7-2-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-2-WEEK) END AS 목
,CASE WHEN (LEVEL*7-1-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-1-WEEK) END AS 금
,CASE WHEN (LEVEL*7-0-WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL*7-0-WEEK) END AS 토
FROM
DUAL
,(SELECT TO_CHAR(LAST_DAY(TO_DATE('201412','YYYYMM')),'DD') AS LAST FROM DUAL)
,(SELECT TO_CHAR(TO_DATE('201412','YYYYMM'),'D')-1 AS WEEK FROM DUAL)
CONNECT BY LEVEL < = CEIL((WEEK + LAST) / 7)
'DB > Oracle 활용' 카테고리의 다른 글
제품별 FROM TO 날짜를 구하려고 합니다. (0) | 2020.02.12 |
---|---|
구간에서 원하는 결과값 구하기 (0) | 2016.06.22 |