Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

File: /media/Research/41a.

sql
/*---- 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.

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