今天小麦苗给大家分享的是Oracle用SQL打印日历。
Oracle用SQL打印日历
1.1 打印当月日历
SELECT MAX(DECODE(DOW, 1, D, NULL)) SUN,
MAX(DECODE(DOW, 2, D, NULL)) MON,
MAX(DECODE(DOW, 3, D, NULL)) TUE,
MAX(DECODE(DOW, 4, D, NULL)) WED,
MAX(DECODE(DOW, 5, D, NULL)) THU,
MAX(DECODE(DOW, 6, D, NULL)) FRI,
MAX(DECODE(DOW, 7, D, NULL)) SAT
FROM (SELECT ROWNUM D,
ROWNUM - 2 + TO_NUMBER(TO_CHAR(TRUNC(SYSDATE, 'MM'), 'D')) P,
TO_CHAR(TRUNC(SYSDATE, 'MM') - 1 + ROWNUM, 'D') DOW
FROM ALL_OBJECTS
WHERE ROWNUM <=
TO_NUMBER(TO_CHAR(LAST_DAY(TO_DATE(SYSDATE)), 'DD')))
GROUP BY TRUNC(P / 7)
ORDER BY sun NULLS FIRST;