This Oracle tutorial explains how to use the WHILE LOOP in Oracle with syntax and examples.
In Oracle, you use a WHILE LOOP when you are not sure how many times you will execute the loop body and the loop body may not execute even once.
The syntax for the WHILE Loop in Oracle/PLSQL is:
The condition is tested each pass through the loop. If condition evaluates to TRUE, the loop body is executed. If condition evaluates to FALSE, the loop is terminated.
The statements of code to execute each pass through the loop.
Let's look at a WHILE LOOP example in Oracle:
In this WHILE LOOP example, the loop would terminate once the monthly_value exceeded 4000 as specified by:
The WHILE LOOP will continue while monthly_value <= 4000. And once monthly_value is > 4000, the loop will terminate.