给定2个日期(StartDate和EndDate),我该如何在Pl / SQL中生成季度周期。
例子:
Start Date: 01-JAN-2009 End Date: 31-DEC-2009
预期产量:
StartDate EndDate 01-JAN-2009 31-MAR-2009 01-APR-2009 30-JUN-2009 01-JUL-2009 30-SEP-2009 01-OCT-2009 31-DEC-2009
SELECT ADD_MONTHS( TRUNC(PARAM.start_date, 'Q'), 3*(LEVEL-1) ) AS qstart , ADD_MONTHS( TRUNC(PARAM.start_date, 'Q'), 3*(LEVEL) ) -1 AS qend FROM ( SELECT TO_DATE('&start_date') AS start_date , TO_DATE('&end_date') AS end_date FROM DUAL ) PARAM CONNECT BY ADD_MONTHS( TRUNC(PARAM.start_date, 'Q'), 3*(LEVEL) ) -1 <= PARAM.end_date
参数规则,您可能需要调整查询以适合您的目的: