Using Exit Statement in Oracle

This Oracle tutorial explains how to use the EXIT declaration in Oracle with syntax and examples.

Description

In Oracle, the EXIT announcement is most commonly used to terminate LOOP statements.

Syntax

The syntax for the EXIT announcement in Oracle/PLSQL is:

EXIT [WHEN boolean_condition];

Parameters or Arguments

boolean_condition Optional. It is the condition to terminate the LOOP.

Example

Let’s look at an EXIT Example in Oracle/PLSQL:

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.