PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Genera serie di mesi per ogni riga in Oracle

Questo dovrebbe fare il trucco (ignora la clausola with; sta solo imitando la tua tabella tst senza dover creare fisicamente la tabella):

with tst as (select 1 id, to_date('2014-02-15','yyyy-mm-dd') st_date, to_date('2014-07-01','yyyy-mm-dd') en_date from dual union all
             select 2 id, to_date('2014-03-15','yyyy-mm-dd') st_date, to_date('2014-04-01','yyyy-mm-dd') en_date from dual)
select id, add_months(trunc(st_date, 'month'), level -1) mnth
from   tst
connect by level <= months_between(trunc(en_date, 'mm'), trunc(st_date, 'mm')) + 1
           and prior id = id
           and prior dbms_random.value is not null;

        ID MNTH      
---------- ----------
         1 2014-02-01
         1 2014-03-01
         1 2014-04-01
         1 2014-05-01
         1 2014-06-01
         1 2014-07-01
         2 2014-03-01
         2 2014-04-01