Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 The Oracle FOR Keyword      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.

Term: FOR

Definition:
The Oracle FOR keyword is used in defining a FOR LOOP. A for loop is typically used to iterate over PL/SQL code, performing one or more actions.

Example syntax for a FOR LOOP is shown below:

FOR <var> IN <start>..<finish> LOOP
<loop_body>
END LOOP;


The <loop_body> is where calculations are done, results are processed, INSERTs, DELETEs or UPDATEs are performed, or other code is executed.

This example FOR LOOP counts from 1 to 5:

BEGIN
FOR i IN 1..5 LOOP
DBMS_OUTPUT.PUT_LINE('Loop counter is ' || i);
END LOOP;
END;/


The line FOR i IN 1..5 LOOP tells the loop's internal counter to start at 1 and continue looping until the counter reaches 5.

The counter can also be an expression which tests one or more conditions, for example, the number of rows inserted, the time and/or date, or the value of a variable.

The line beginning with DBMS_OUTPUT is the body of the loop where code is executed. Nearly any valid SQL, DML, or DDL statements or statements can be placed in the body of the loop to be executed, processed, or acted upon.
Related Code Snippets:
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 200 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?