Using REPEAT UNTIL LOOP in Oracle

This Oracle tutorial explains how to use the REPEAT UNTIL LOOP in Oracle with syntax and examples.

Description

Oracle doesn’t have a REPEAT UNTIL LOOP, but you can emulate one with a LOOP statement.

Syntax

The syntax for emulating a REPEAT UNTIL LOOP in Oracle/PLSQL is:

LOOP

   {...statements...}

   EXIT [ WHEN boolean_condition ];

END LOOP;

Parameters or Arguments

statements The statements of code to execute each ignore through the loop. boolean_condition Optional. It is the condition to terminate the loop.

Note

You would use an emulated REPEAT UNTIL LOOP when you do not know how many instances you choose the loop physique to execute. The REPEAT UNTIL LOOP would terminate when a positive condition was met.

Example

Let’s seem to be at an example of how to emulate a REPEAT UNTIL LOOP in Oracle/PLSQL:

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

In this example, we prefer the loop to repeat till monthly_value is greater than 4000, so we use the EXIT WHEN statement.

EXIT WHEN monthly_value > 4000;

Now, the LOOP would repeat until the monthly_value handed 4000.