1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| with MaTable as
(
select 1 as rid, date '2013-06-15' as dt_deb, date '2013-08-25' as dt_fin from dual union all
select 2 , date '2012-01-13' , date '2012-01-27' from dual union all
select 3 , date '2012-03-13' , date '2012-04-10' from dual union all
select 4 , date '2012-06-15' , date '2012-07-15' from dual union all
select 5 , date '2013-12-02' , date '2014-02-01' from dual
)
SELECT rid
, greatest(dt_deb, trunc(add_months(dt_deb, level - 1), 'mm')) AS dt_deb
, least(dt_fin, last_day(add_months(dt_fin, level - 1 - months_between(trunc(dt_fin, 'mm'), trunc(dt_deb, 'mm'))))) AS dt_fin
FROM MaTable
CONNECT BY level <= months_between(trunc(dt_fin, 'mm'), trunc(dt_deb, 'mm')) + 1
AND PRIOR rid = rid
AND PRIOR sys_guid() IS NOT NULL
ORDER BY 1, 2; |
Partager