【发布时间】:2018-07-20 02:03:52
【问题描述】:
语句 RAISE 是否隐式回滚(在块 EXCEPTION 中)?
提前致谢
【问题讨论】:
标签: sql database oracle exception
语句 RAISE 是否隐式回滚(在块 EXCEPTION 中)?
提前致谢
【问题讨论】:
标签: sql database oracle exception
没有。块作为一个整体将在失败时回滚,但 raise 语句本身不会执行回滚。
例如,此块失败并隐式回滚(就像它是 SQL insert 等一样):
begin
insert into demo(id) values(1);
dbms_output.put_line(sql%rowcount || ' row inserted');
raise program_error;
exception
when program_error then raise;
end;
ERROR at line 1:
ORA-06501: PL/SQL: program error
ORA-06512: at line 6
SQL> select * from demo;
no rows selected
但是这个块并没有回滚,即使里面有一个raise:
begin
begin
insert into demo(id) values(1);
dbms_output.put_line(sql%rowcount || ' row inserted');
raise program_error;
exception
when program_error then
dbms_output.put_line('Raising exception');
raise;
end;
exception
when program_error then null;
end;
1 row inserted
Raising exception
PL/SQL procedure successfully completed.
SQL> select * from demo;
ID
----------
1
1 row selected.
【讨论】: