CoderZone.org

Category: >> Oracle PL/SQL >> Basic FOR LOOP example Bookmark and Share

<< lastnext >>

Snippet Name: Basic FOR LOOP example

Description: 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.

Comment: (none)

Author: CoderZone
Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: February 27th, 2009

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 is even');
     ELSE
         INSERT INTO temp VALUES (i, x, 'i is odd');
     END IF;
 
     x := x + 100;        
    END LOOP;
    COMMIT;
END;
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 6