Oracle
 sql >> Database >  >> RDS >> Oracle

Oracle SQL primo e ultimo giorno del trimestre di qualsiasi anno

Potresti fare quanto segue:

with q(qtr) as(
  select add_months(
                    DATE '2013-01-01'
                    , (level-1)*3
                    )
    from dual 
  connect by level <= 4
)
select qtr                          as first_day
     , last_day(add_months(qtr, 2)) as last_day
  from q

Risultato:

FIRST_DAY     LAST_DAY
-----------  -----------
01.01.2013    31.03.2013
01.04.2013    30.06.2013
01.07.2013    30.09.2013
01.10.2013    31.12.2013

Demo SQLFIddle