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!

Insert a dummy records with cross join lateral

Sid_ Z.May 22 2023

Hi All,

Oracle version - 19c

I have below code and I need correction in that.

If I have a one record then I need to insert next 5 subsequent date wise records 0 quantity. My current solution is not giving me the correct quantity.

with t as (
 select '111' id, to_date('22-MAY-23','DD-MON-YY') as startdate,  2.5 qty from dual
 )
select t.id
      ,l.startdate
      ,t.qty
from   t
      cross join
      lateral (select t.startdate+(level-1) as startdate
              from   dual
              connect by level <= 5)  l
;

My output should be as follows:

ID STARTDATE QTY

111 22-MAY-23 2.5
111 23-MAY-23 0
111 24-MAY-23 0
111 25-MAY-23 0
111 26-MAY-23 0

Regards,

Sid

This post has been answered by gsalem-Oracle on May 22 2023
Jump to Answer
Comments
Post Details
Added on May 22 2023
4 comments
763 views