WITH t AS
( SELECT TO_DATE('201201', 'yyyymm') + LEVEL - 1 dt
FROM dual
CONNECT BY LEVEL <= 4000 )
SELECT TO_CHAR(dt, 'YYYY.MM.DD')AS current_Date
, TO_CHAR(TRUNC(dt, 'iw'), 'yyyy') AS Year
, TO_CHAR(TRUNC(dt, 'iw'), 'MM') AS Month
, 'W' || LPAD(( TRUNC(dt, 'iw') - NEXT_DAY(TRUNC(TRUNC(dt, 'iw'), 'yy') - 1, 2)) / 7 + 1, 2, '0')
|| CASE WHEN TO_CHAR(TRUNC(dt, 'iw'), 'mm') != TO_CHAR(TRUNC(dt, 'iw') + 6, 'mm')
THEN DECODE(TO_CHAR(TRUNC(dt, 'iw'), 'mm'), TO_CHAR(dt, 'mm'), 'A', 'B')
END AS Week_Of_52
FROM t;
Oracle 관련2012. 6. 12. 13:59