/*---- 41a.sql -----*/ /* 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. */ set echo on; drop table TEMP; create table TEMP (col1 number(9,4), col2 number(4), text char(55)); / DECLARE x NUMBER := 100; BEGIN FOR i IN 1..10 LOOP IF MOD(i,2) = 0 THEN -- i is even 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;