Implementing continue in Oracle pl/SQL

Source: Internet
Author: User
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;

 

-- Custom exception
DECLARE
Pi constant number (9, seven): = 3.1415927;
Radius INTEGER (5 );
Area NUMBER (14, 2 );
E_userdefinedexception exception;
Pragma exception_init (e_userdefinedexception,-1401 );
Begin
RADIUS: = 0;

Loop
RADIUS: = radius + 1;

Begin
If radius = 4
Then
Raise e_userdefinedexception;
Else
Area: = pI * power (radius, 2 );

Insert into areas
VALUES (radius, area );

Exit when area> 100;
End if;
EXCEPTION
WHEN e_userdefinedexception
THEN
NULL;
END;
End loop;

COMMIT;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
RAISE;
END;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.