Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Generating months between two dates

Hi

I have posted this already but it is mising now.

Somebody has replied with following query to generate months between 30-JAN-200 and 15-MAR-2011

select
distinct(last_day(to_date(td.end_date + 1 - rownum))) PFMONTH
from
all_objects,
(-- this is just to easily substitute dates for the example...
select to_date('30-JAN-2000') start_date
,to_date('15-MAR-2011') end_date
FROM DUAL ) td
where
trunc(td.end_date + 1 - rownum,'MM') >= trunc(td.start_date,'MM')
order by 1

I have to do the same for each employee

data

select 1 empid,to_date('03/1995','mm/yyyy') start_dt,to_date('06/1995','mm/yyyy') from dual union all
select 2 empid,to_date('04/1995','mm/yyyy') start_dt,to_date('06/1995','mm/yyyy') from dual

expected result

empid |month_year

1 03/95
1 04/95
1 05/95
1 06/95

2 04/95
2 05/95
2 06/95

Please help

This post has been answered by Barbara Boehmer on Apr 22 2023
Jump to Answer
Comments
Post Details
Added on Apr 22 2023
3 comments
348 views