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!

PLSQL while loop iterate

Devel007May 30 2018 — edited May 31 2018

Hi

Could someone help me with this While Loop Procedure. Need to iterate data one by one from table and insert something in other table. There is something wrong in my procedure now

---------------------------------------

select * from LOOP_TEST

ID

2

3

4

5

8

12

---------------------------------------

BEGIN_PROC

DECLARE

rownum    integer;

custid       integer;

BEGIN

custid := SELECT max(id) FROM LOOP_TEST;

rownum := SELECT count(id) FROM LOOP_TEST;

while rownum > 0 loop

INSERT INTO loop_test_2

values(1);

SELECT id FROM LOOP_TEST

WHERE id = custid

ORDER BY id DESC

LIMIT 1;

rownum := rownum-1;

END loop;

COMMIT;

END;

END_PROC;

--------------------------------------------------------------------

This post has been answered by Jarkko Turpeinen on May 30 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2018
Added on May 30 2018
12 comments
904 views