[DATABASE/ORACLE] 해당 월 달력 조회하기
■ 해당 월 달력을 조회하는 방법을 보여준다. ▶ 예제 코드 (SQL)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SELECT CASE WHEN (LEVEL * 7 - 6 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 6 - WEEK) ELSE '' END AS 일 ,CASE WHEN (LEVEL * 7 - 5 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 5 - WEEK) ELSE '' END AS 월 ,CASE WHEN (LEVEL * 7 - 4 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 4 - WEEK) ELSE '' END AS 화 ,CASE WHEN (LEVEL * 7 - 3 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 3 - WEEK) ELSE '' END AS 수 ,CASE WHEN (LEVEL * 7 - 2 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 2 - WEEK) ELSE '' END AS 목 ,CASE WHEN (LEVEL * 7 - 1 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 1 - WEEK) ELSE '' END AS 금 ,CASE WHEN (LEVEL * 7 - 0 - WEEK) BETWEEN 1 AND LAST THEN TO_CHAR(LEVEL * 7 - 0 - WEEK) ELSE '' END AS 토 FROM DUAL ,(SELECT TO_CHAR(LAST_DAY(TO_DATE('202002', 'YYYYMM')), 'DD') AS LAST FROM DUAL) ,(SELECT TO_CHAR(TO_DATE('202002', 'YYYYMM'), 'D') - 1 AS WEEK FROM DUAL) CONNECT BY LEVEL <= CEIL((WEEK + LAST) / 7); |