提高声明

时间:2018-02-09 10:14:02

标签: sql database oracle exception

语句RAISE是否隐式回滚(在块EXCEPTION中)?

提前致谢

1 个答案:

答案 0 :(得分:2)

没有。作为整体的块将在失败时回滚,但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.