Oracle trunc()函数的用法
程序员文章站
2023-12-24 12:32:03
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的其他用法可以参考博文: