Create Table Areas
(
Radius number (5 ),
Area Number (14,2)
);
Method 1: Use GOTO
Declare
Pi constant number (9, seven): = 3.1415927;
Radius INTEGER (5 );
Area Number (14, 2 );
Begin
RADIUS: = 0;
Loop
<Here>
RADIUS: = radius + 1;
If radius = 4
Then
Goto here;
Else
Area: = pI * power (radius, 2 );
Insert into areas
Values (radius, area );
Exit when area> 100;
End if;
End loop;
Commit;
Exception
When others
Then
Rollback;
Raise;
End;
-- Method 2: Use exception
-- System exception
Declare
Pi constant number (9, seven): = 3.1415927;
Radius INTEGER (5 );
Area Number (14, 2 );
Some_variable number (14, 2 );
Begin
RADIUS: = 0;
Loop
Begin
RADIUS: = radius + 1;
Some_variable: = 1/(radius-4 );
Area: = pI * power (radius, 2 );
Insert into areas
Values (radius, area );
Exit when area> 100;
Exception
When zero_divide
Then
NULL;
End;
End loop;
Commit;
Exception
When others
Then
Rollback;
Raise;
End;