sql >> Base de Datos >  >> RDS >> PostgreSQL

Genera series de meses para cada fila en Oracle

Esto debería funcionar (ignora la cláusula with; solo está imitando tu tabla tst sin tener que crear físicamente la tabla):

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