I have the following dates in a table cp:
start_date: 01/01/2017, end_date: 01/08/2017;
start_date: 01/04/2017, end_date: 01/07/2017
I would like to create a record dynamically for each month between these periods. It tried with the following query, but I don't understand why it's not working.
select add_months(cp.end_date, rownum-1) which_month, id
FROM (select '1' as id,
to_date('01/01/2017', 'DD/MM/YYYY') start_date,
to_date('01/08/2017', 'DD/MM/YYYY') end_date
from dual
UNION
select '2' as id,
to_date('01/04/2017', 'DD/MM/YYYY') start_date,
to_date('01/07/2017', 'DD/MM/YYYY') end_date
from dual) cp, all_objects
WHERE ROWNUM <= months_between(cp.end_date, add_months(cp.start_date, -1));
Can you help me?