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!

Generate a week wise data between two dates

Sid_ Z.Jul 19 2022

Hi All,
Oracle version - 19c.
I want to generate the week wise record from a startdate of my record till it reaches to enddate.
My startdate should add next week date and add the record in my result set as below:
My start of the week is Monday 18-Jul-22 so next date will be 25-Jul-22 and then 01-Aug-22 and so on

with t as (
select '111' id, 'AU-1221' as loc, to_date('18-JUL-22') as startdate, to_date('16-JAN-24') as enddate, 0 qty from dual union all
select '222' id, 'Bo-5522' as loc, to_date('18-JUL-22') as startdate, to_date('14-AUG-23') as enddate, 0 qty from dual
)
select * from t;

OUTPUT:

ID    LOC     STARTDATE    ENDDATE     QTY
111   AU-1221   18-JUL-22   16-JAN-24     0
111   AU-1221   25-JUL-22   16-JAN-24     0
111   AU-1221   01-AUG-22   16-JAN-24     0
111   AU-1221   08-AUG-22   16-JAN-24     0
111   AU-1221   15-AUG-22   16-JAN-24     0
111   AU-1221   22-AUG-22   16-JAN-24     0
...

222   Bo-5522   18-JUL-22   14-AUG-23     0
222   Bo-5522   25-JUL-22   14-AUG-23     0
222   Bo-5522   01-AUG-22   14-AUG-23     0
222   Bo-5522   08-AUG-22   14-AUG-23     0
222   Bo-5522   15-AUG-22   14-AUG-23     0
...

Regards,
Sid

This post has been answered by BluShadow on Jul 19 2022
Jump to Answer
Comments
Post Details
Added on Jul 19 2022
6 comments
231 views