--定义EXCEPTION
SET SERVEROUTPUT ON
DECLARE
A exception;
BEGIN
RAISE A;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('EXCEPTION A!');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line('OTHERS EXCEPTION!');
END;
--结果
--EXCEPTION A!
--EXCEPTION 001
SET SERVEROUTPUT ON
DECLARE
A exception;
B exception;
BEGIN
RAISE B;
BEGIN
RAISE A;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('IN EXCEPTION A!');
WHEN B THEN
DBMS_OUTPUT.put_line('IN EXCEPTION B!');
END;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION A!');
WHEN B THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION B!');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line('OTHERS EXCEPTION!');
END;
--结果
--OUT EXCEPTION B!
--EXCEPTION 002
SET SERVEROUTPUT ON
DECLARE
A exception;
B exception;
BEGIN
BEGIN
RAISE A;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('IN EXCEPTION A!');
WHEN B THEN
DBMS_OUTPUT.put_line('IN EXCEPTION B!');
END;
RAISE B;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION A!');
WHEN B THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION B!');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line('OTHERS EXCEPTION!');
END;
--结果
--IN EXCEPTION A!
--OUT EXCEPTION B!
--EXCEPTION 003
SET SERVEROUTPUT ON
DECLARE
A exception;
B exception;
BEGIN
BEGIN
RAISE A;
EXCEPTION
WHEN B THEN
DBMS_OUTPUT.put_line('IN EXCEPTION B!');
END;
RAISE B;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION A!');
WHEN B THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION B!');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line('OTHERS EXCEPTION!');
END;
--结果
--OUT EXCEPTION A!
--EXCEPTION 004
SET SERVEROUTPUT ON
DECLARE
A exception;
B exception;
C exception;
BEGIN
RAISE C;
BEGIN
RAISE A;
EXCEPTION
WHEN B THEN
DBMS_OUTPUT.put_line('IN EXCEPTION B!');
END;
RAISE B;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION A!');
WHEN B THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION B!');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line('OTHERS EXCEPTION!');
END;
--结果
--OTHERS EXCEPTION!
--EXCEPTION 005
SET SERVEROUTPUT ON
DECLARE
A exception;
B exception;
C exception;
BEGIN
BEGIN
RAISE A;
EXCEPTION
WHEN A THEN
RAISE C;
WHEN B THEN
DBMS_OUTPUT.put_line('IN EXCEPTION B!');
END;
RAISE B;
EXCEPTION
WHEN A THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION B!');
WHEN B THEN
DBMS_OUTPUT.put_line('OUT EXCEPTION B!');
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.put_line('OTHERS EXCEPTION!');
END;
--结果:
--OTHERS EXCEPTION!