Sunday, January 11, 2009

Loop Statement

Oracle/PLSQL: Loop Statement


The syntax for the LOOP statement is:

LOOP
{.statements.}
END LOOP;

You would use a LOOP statement when you are not sure how many times you want the loop body to execute and you want the loop body to execute at least once.

The LOOP statement is terminated when it encounters either an EXIT statement or when it encounters an EXIT WHEN statement that evaluated to TRUE.

Let's take a look at an example:

LOOP
monthly_value := daily_value * 31;
EXIT WHEN monthly_value > 4000;
END LOOP;

In this example, the LOOP would terminate when the monthly_value exceeded 4000.

No comments:

Post a Comment