• 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

syntax and example of WHILE Loop in oracle sql

WHILE Loop in Oracle PLSQL

November 23, 2012 by techhoneyadmin

A WHILE Loop in Oracle PLSQL is used when we are not sure as to how many times the loop’s body should be executed.

Unlike LOOP statement, a WHILE LOOP may not get executed even once as the condition to execute a WHILE LOOP is evaluated before execution of the loop.

A WHILE LOOP gets terminated whenever the condition to execute the loop evaluates to false.

The Syntax for the WHILE LOOP in Oracle PLSQL is:
WHILE condition
LOOP
{
Statements to be executed;
}
END LOOP;

Example of a WHILE LOOP in Oracle PLSQL is:

WHILE sum <= 35
LOOP
{
  sum := sum + 1;
}
END LOOP;

The above loop will execute the “sum := sum+1” statement and as soon as the value of the “sum” variable crosses 35 the loop will terminate.
It may happen that the variable “sum” is already assigned a value higher than 35, in this case the WHILE LOOP will not get executed even once.


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

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