How to exit from a procedure in Oracle


To exit from function is easy, just put “RETURN”

CREATE OR REPLACE FUNCTION MIS.FC_GET_ACCRUAL_COM(VAGR IN VARCHAR2) RETURN NUMBER IS
VNUM NUMBER;
BEGIN
SELECT AGR INTO VNUM FROM TAGR WHERE AGR = ‘AA’;

IF VNUM = 0 THEN
RETURN 1;
ELSE
RETURN 2;
END IF;
RETURN VNUM;
EXCEPTION WHEN OTHERS THEN
RETURN 0;
END;
/

To exit from procedure also easy, just use “RAISE”

CREATE OR REPLACE PROCEDURE TEST_EXIT
IS
HOI EXCEPTION;
BEGIN
RAISE HOI;
DBMS_OUTPUT.PUT_LINE (‘hoi’);
EXCEPTION
WHEN HOI
THEN
NULL;
END;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: