sample1:
BEGIN
insert into test_table values(1,11);
Declare
i number:=1;
Cu_ex Exception;
Begin
insert into test_table values(2,22);
If (i=1) then
Raise Cu_ex;
End if;
DBMS_OUTPUT.put_line('TEST');
commit;
Exception
When Cu_ex then
Raise_application_error(-20000,'has an customer error'||sqlerrm);
When others then
Raise_application_error(-20001,'has an error'||sqlerrm);
End;
END;
/
在这个例子中,两条insert都会被回滚。
sample2:
BEGIN
insert into test_table values(1,11);
Declare
i number:=1;
Cu_ex Exception;
Begin
insert into test_table values(2,22);
If (i=1) then
Raise Cu_ex;
End if;
DBMS_OUTPUT.put_line('TEST');
commit;
Exception
When Cu_ex then
Raise_application_error(-20000,'has an customer error'||sqlerrm);
When others then
Raise_application_error(-20001,'has an error'||sqlerrm);
End;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
/
在这个例子中,两条insert都不会回滚,因为异常被捕捉并处理了,并没有传递到调用环境中。