DECLARE x NUMBER := 0; counter NUMBER := 0; BEGIN FOR i IN 1..4 LOOP x := x + 1000; counter := counter + 1; INSERT INTO temp VALUES (x, counter, 'outer loop'); /* start an inner block */ DECLARE x NUMBER := 0; -- this is a local version of x BEGIN FOR i IN 1..4 LOOP x := x + 1; -- this increments the local x counter := counter + 1; INSERT INTO temp VALUES (x, counter, 'inner loop'); END LOOP; END; END LOOP; COMMIT; END;
COL1 COL2 MESSAGE ------- -------- ------------- 1000 1 OUTER loop 1 2 inner loop 2 3 inner loop 3 4 inner loop 4 5 inner loop 2000 6 OUTER loop 1 7 inner loop 2 8 inner loop 3 9 inner loop 4 10 inner loop 3000 11 OUTER loop 1 12 inner loop 2 13 inner loop 3 14 inner loop 4 15 inner loop 4000 16 OUTER loop 1 17 inner loop 2 18 inner loop 3 19 inner loop 4 20 inner loop 20 records selected.