列出日期内所有月份
---恢复内容开始---
1
2
3
4
5
6
7
8
9
|
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<=@monthsoracle: SELECT TO_CHAR( add_months(to_date( '2011-03' , 'yyyy-mm' ), ROWNUM - 1), 'YYYY-MM' ) AS yearmonthFROM DUAL CONNECT BY ROWNUM <= ( SELECT months_between(to_date( '2012-07' , 'yyyy-mm' ), to_date( '2011-03' , 'yyyy-mm' )) FROM dual) |
---恢复内容结束---