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!

While loop Statement Error in SQL script

4adb2b89-74ff-4b12-aac7-b1b4274e576dMay 26 2019 — edited May 26 2019

I need to insert data into new target table from jan1st to march28th by iterating through dates in Oracle SQL.

I have tried below script, bt its throwing errors

DECLARE

  from_dt DATE := to_date('01/01/2019', 'mm/dd/yyyy');

  to_dt   DATE :=  to_date('01/04/2019', 'mm/dd/yyyy');

  fin_dt  DATE := to_date('03/28/2019', 'mm/dd/yyyy');

begin

while (from_dt < fin_dt)

loop

insert into New_target_table  as select  /*statement*/

and greatest(CE.UPDATE_TS, CES.Update_ts)  > from_dt

and greatest(CE.UPDATE_TS, CES.Update_ts)  < to_dt ; 

end loop;

set  from_dt:= from_dt + 3;

set  to_dt := DATEADD(DAY, 3, from_dt);

END;

Comments
Post Details
Added on May 26 2019
7 comments
401 views