The EXIT and EXIT WHEN statements enable you to escape out of the control of a loop.
The format of the EXIT loop is
EXIT;
To terminate a loop, simply follow your condition with the EXIT statement.
This is common when using IF statements.
The Syntax for the EXIT WHEN Loop:
EXIT WHEN <condition is true>;
The EXIT WHEN statement enables you to specify the condition required to exit the execution of the loop.
In this case, no IF statement is required.
SQL>
SQL> DECLARE
2 v_Radius NUMBER := 2;
3 BEGIN
4 WHILE TRUE LOOP
5 DBMS_OUTPUT.PUT_LINE('The Area is ' ||
6 3.14 * v_Radius * v_Radius);
7 IF v_Radius = 10 THEN
8 EXIT;
9 END IF;
10 v_Radius := v_Radius + 2 ;
11 END LOOP;
12 END;
13 /
The Area is 12.56
The Area is 50.24
The Area is 113.04
The Area is 200.96
The Area is 314
PL/SQL procedure successfully completed.
SQL>