0% found this document useful (0 votes)
9 views1 page

PL/SQL For Loop Example with Insertions

This SQL script uses a FOR loop to insert 10 rows into a table. The FOR loop iterates from 1 to 10, and on each iteration inserts the current loop index, a counter variable that increments by 100 each time, and either the string 'i (even)' or 'i (odd)' depending on whether the loop index is even or odd.

Uploaded by

Kungfu Sparta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

PL/SQL For Loop Example with Insertions

This SQL script uses a FOR loop to insert 10 rows into a table. The FOR loop iterates from 1 to 10, and on each iteration inserts the current loop index, a counter variable that increments by 100 each time, and either the string 'i (even)' or 'i (odd)' depending on whether the loop index is even or odd.

Uploaded by

Kungfu Sparta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

File: /media/Research/41a.

sql
/*---- [Link] -----*/ /* Example of a for-loop in PL/SQL */ /* ** ** ** ** */ This block uses a simple FOR loop to insert 10 rows into a table. The values of a loop index, counter variable, and either of two character strings are inserted. Which string is inserted depends on the value of the loop index.

Page 1 of 1

set echo on; drop table TEMP; create table TEMP col1 col2 text / DECLARE x NUMBER := 100; BEGIN FOR i IN 1..10 LOOP IF MOD(i,2) = 0 THEN -- i is even ( number(9,4), number(4), char(55));

INSERT INTO temp VALUES (i, x, 'i (even)'); ELSE INSERT INTO temp VALUES (i, x, 'i (odd)'); END IF; x := x + 100; END LOOP; COMMIT; END; / select * from TEMP;

You might also like