您的位置:首页 > 数据库 > Oracle

ORACLE 存储过程异常捕获并抛出

2017-09-20 18:51 316 查看
DECLARE

--声明异常

some_kinds_of_err EXCEPTION; -- Exception to indicate an error condition

v_ErrorCode NUMBER; -- Variable to hold the error message code

v_ErrorText VARCHAR2(200); -- Variable to hold the error message text

BEGIN

--...

--抛出异常

IF ( ... ) THEN --(括号内填抛出异常的条件)

RAISE some_kinds_of_err;

END IF;

--...

EXCEPTION

--捕捉异常

WHEN some_kinds_of_err THEN

/* do something to Handler the errors */

null;

--捕捉其他异常,并获得 捕获异常的内容

WHEN OTHERS THEN

v_ErrorCode := SQLCODE;

v_ErrorText := SUBSTR(SQLERRM, 1, 200);

-- Note the use of SUBSTR here.

dbms_output.put_line(v_ErrorCode || '::'||v_ErrorText);

END;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息