Sunday, January 11, 2009

While Loop

Oracle/PLSQL: While Loop


The syntax for the WHILE Loop is:

WHILE condition
LOOP
{.statements.}
END LOOP;

You would use a WHILE Loop when you are not sure how many times you will execute the loop body. Since the WHILE condition is evaluated before entering the loop, it is possible that the loop body may not execute even once.

Let's take a look at an example:

WHILE monthly_value <= 4000
LOOP
monthly_value := daily_value * 31;
END LOOP;

In this example, the WHILE Loop would terminate once the monthly_value exceeded 4000.

No comments:

Post a Comment