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

Term: WHILE

Definition:
A WHILE Loop is used when you want to repeatedly execute statements in a loop body until the specified condition occurs. The condition may be a set value (3, 50, 22,000, etc) or the result of an evaluated expression (temperature < 50).

Example Syntax:
The syntax for the WHILE Loop is:

WHILE (<condition>)
LOOP
{statements to execute}
END LOOP;


An important thing to note is that the WHILE condition is evaluated before entering the loop. Because of this it is possible that the loop body may never get to execute even once if the condition evaluates to false. For example, because '1' will never equal '2', this loop will never execute:

WHILE 1 = 2
LOOP
DBMS_OUTPUT.PUT_LINE('1 equals 2');
END LOOP;


In this example, the WHILE Loop would terminate once the daily_sales exceeded 1000:

WHILE daily_sales <= 1001
LOOP
DBMS_OUTPUT.PUT_LINE('Sales are less than 1000');
END LOOP;


Want to expand, correct, or add to this information? Please contact us!

Related Code Snippets:
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 183 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?