PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Gere séries de meses para cada linha no Oracle


Isso deve resolver o problema (ignore a cláusula with; está apenas imitando sua tabela tst sem ter que criar fisicamente a tabela):
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