SELECT *
FROM (
SELECT TO_CHAR (BASE_MON + LEVEL - 1, 'DD') DD,
CASE
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 7 THEN '토'
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 6 THEN '금'
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 5 THEN '목'
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 4 THEN '수'
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 3 THEN '화'
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 2 THEN '월'
WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 1 THEN '일'
ELSE ''
END AS YOIL
FROM
(SELECT TO_DATE ('201712', 'YYYYMM') BASE_MON FROM DUAL)
CONNECT BY BASE_MON + LEVEL - 1 <= LAST_DAY(BASE_MON) ) ;
위 쿼리를 조회하면
DD YOIL
01 금
02 토
'''
이런식으로 표기가 되는데
아래처럼 표기하는 방법이 있을까요?
01 02 03 04 ...
금 토 일 월 ...
WITH T AS ( SELECT * FROM ( SELECT TO_CHAR (BASE_MON + LEVEL - 1, 'DD') DD, CASE WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 7 THEN '토' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 6 THEN '금' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 5 THEN '목' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 4 THEN '수' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 3 THEN '화' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 2 THEN '월' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 1 THEN '일' ELSE '' END AS YOIL FROM (SELECT TO_DATE ('201712', 'YYYYMM') BASE_MON FROM DUAL) CONNECT BY BASE_MON + LEVEL - 1 <= LAST_DAY(BASE_MON) ) ) SELECT * FROM T PIVOT ( MIN(YOIL) FOR DD IN ( '01','02','03','04' )) -- 추가하세요.
SELECT * FROM ( SELECT TO_CHAR (BASE_MON + LEVEL - 1, 'DD') DD, CASE WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 7 THEN '토' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 6 THEN '금' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 5 THEN '목' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 4 THEN '수' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 3 THEN '화' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 2 THEN '월' WHEN TO_CHAR (BASE_MON + LEVEL - 1, 'D') = 1 THEN '일' ELSE '' END AS YOIL FROM (SELECT TO_DATE ('201712', 'YYYYMM') BASE_MON FROM DUAL) CONNECT BY BASE_MON + LEVEL - 1 <= LAST_DAY(BASE_MON) ) pivot( MIN(yoil) FOR DD IN ('01', '02', '03', '04', '05' ,'06', '07','08' .......) )
SELECT * FROM (SELECT TO_CHAR(base_mon + LEVEL - 1, 'dd') dd , TO_CHAR(base_mon + LEVEL - 1, 'dy') dy FROM (SELECT TO_DATE('201712', 'yyyymm') base_mon FROM dual) CONNECT BY LEVEL <= LAST_DAY(base_mon) - base_mon + 1 ) PIVOT (MIN(dy) FOR dd IN ( '01' "01", '02' "02", '03' "03", '04' "04", '05' "05" , '06' "06", '07' "07", '08' "08", '09' "09", '10' "10" , '11' "11", '12' "12", '13' "13", '14' "14", '15' "15" , '16' "16", '17' "17", '18' "18", '19' "19", '20' "20" , '21' "21", '22' "22", '23' "23", '24' "24", '25' "25" , '26' "26", '27' "27", '28' "28", '29' "29", '30' "30" , '31' "31") ) ;