【问题标题】:Raise statement提高声明
【发布时间】:2018-07-20 02:03:52
【问题描述】:

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

提前致谢

【问题讨论】:

    标签: sql database oracle exception


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      • 2019-05-21
      • 2019-01-24
      相关资源
      最近更新 更多