A FOR Loop in Oracle PLSQL is used to execute a portion of code i.e. the body of loop, a fixed number of times.
The Syntax for the FOR LOOP in Oracle PLSQL is:
FOR loop_counter IN [REVERSE] low_number .. high_number
LOOP
{
Statements to be executed;
}
END LOOP;
Example of a FOR Loop in Oracle PLSQL is:
FOR cnt IN 1..35 LOOP { sum := sum + 1; } END LOOP;
The above loop will execute the “sum := sum + 1; statement 35 times. The loop will start counting from 1 and ends at 35.
Example of a FOR Loop IN REVERSE in Oracle PLSQL is:
FOR cnt IN REVERSE 1..30 LOOP { sum := sum + 1; } END LOOP;
The above loop will execute the “sum := sum+1; statement 30 times. The loop will start counting from 30 and ends at 1 looping backwards.