SELECT to_number(TO_CHAR(add_months(trunc(sysdate, 'yy'), ROWNUM - 1), 'MM')) as month FROM DUALCONNECT BY ROWNUM <= (select months_between(trunc(sysd ...
SELECT to_number(TO_CHAR(add_months(trunc(sysdate, 'yy'), ROWNUM - 1), 'MM')) as month
FROM DUAL
CONNECT BY ROWNUM <=
(select months_between(trunc(sysdate, 'mm'), trunc(sysdate, 'yy')) + 1
from dual);
當然,也可以指定具體的時間段,只要把months_between裡面的兩個日期改成具體的日期就行,
其中,trunc(sysdate, 'mm')是返回當月的第一天,trunc(sysdate, 'yy')是返回當年的第一天。
trunc的其他用法可以參考博文: