如何使用查询获取2个给定日期之间的月份列表?

问题描述:

我有2个约会,例如2011年3月28日和2011年6月29日.我需要一个SQL查询,该查询将显示这两个日期之间的月份,包括包含日期的月份,即.六月,五月,四月和三月.

I have 2 dates, say 28-Mar-2011 and 29-Jun-2011. I need an sql query that will display the months between these 2 dates including the months containing the dates, ie. June, May, April and March.

类似这样的东西

SQL> ed
Wrote file afiedt.buf

    select to_char( add_months( start_date, level-1 ), 'fmMonth' )
      from (select date '2011-03-30' start_date,
                   date '2011-06-29' end_date
              from dual)
     connect by level <= months_between(
                           trunc(end_date,'MM'),
                           trunc(start_date,'MM') )
  *                      + 1
SQL> /

TO_CHAR(ADD_MONTHS(START_DATE,LEVEL-
------------------------------------
March
April
May
June

应该工作.