---恢复内容开始---
sqlserver:
declare @begin datetime,@end datetime
set @begin=‘2012-1-5‘
set @end=‘2012-11-3‘
declare @months int
set @months=DATEDIFF(month,@begin,@end)
select convert(varchar(7),DATEADD(month,number,@begin) ,120) AS 月份
from master.dbo.spt_values
where type=‘p‘ AND number<=@months
oracle:
SELECT TO_CHAR( add_months(to_date(‘2011-03‘, ‘yyyy-mm‘), ROWNUM - 1), ‘YYYY-MM‘ ) AS yearmonth
FROM DUAL
CONNECT BY ROWNUM <=
(SELECT months_between(to_date(‘2012-07‘, ‘yyyy-mm‘), to_date(‘2011-03‘, ‘yyyy-mm‘))
FROM dual)
---恢复内容结束---
原文:https://www.cnblogs.com/xiaolongzi/p/9618446.html