Quick Search:
 
 Oracle PL/SQL: Basic FOR LOOP example Jump to:  
Category: >> Oracle PL/SQL >> Basic FOR LOOP example  

<< 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)

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;


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org