• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql
You are here: Home / Oracle / loop / FOR Loop in Oracle PLSQL

FOR Loop in Oracle PLSQL

November 23, 2012 by techhoneyadmin

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.


Filed Under: loop Tagged With: FOR Loop in oracle plsql, FOR Loop in oracle sql, FORLOOPPLSQL, how to use FOR Loop in oracle database query, how to use FOR Loop in oracle plsql, how to use FOR Loop in oracle sql, syntax and example of FOR Loop in oracle database query, syntax and example of FOR Loop in oracle plsql, syntax and example of FOR Loop in oracle sql, using FOR Loop in oracle database query, using FOR Loop in oracle plsql, using FOR Loop in oracle sql

Copyright © 2023 · Parallax Pro on Genesis Framework · WordPress · Log in