do something 1;
commit;
do something 2;
commit;
do something 3;
exception  
  when   others   then  
  rollback;  1 如果在do something 2中出现错误。是否会rollback 到 do something 1之前呢。
2 如果在do something 2中出现错误。是否do something 3 还会被执行呢。
3 如果想实现1和2中的两个效果。该如何来做呢。

解决方案 »

  1.   

    1.不会,因为你这前已经commit了.
    2.不会继续向下执行,会立即跳到异常块去.
    3.
    do something 1; 
    do something 2; 
    commit; 
    exception  
      when  others  then  
      do something 3; 
      commit;
      

  2.   

    这样行吗
    do something 1;
    commit;
    do something 2;
    exception 
      when  others  then 
      rollback;  
    commit;
    do something 3;或者这样呢
    do something 1;
    commit;
    exception 
      when  others  then 
      rollback; 
    do something 2;
    exception 
      when  others  then 
      rollback;  
    commit;
    do something 3;
    exception 
      when  others  then 
      rollback; 
      

  3.   

    do something 1; 
    do sommeting 2;
    exception 
    when others then 
    rollback;
    commit;
    do something 3;
    commit;
      

  4.   

    1、如果在do something 2中出现错误,只能rollback到something 1之后。
    2、如果在do something 2中出现错误,后面的语句都不被执行。
    3、如果你想rollback到do something 1 之前,建议你建一张临时表,记得好像有回滚点之说,你百一下吧。
      

  5.   

    if else 控制,加回滚点
      

  6.   

    可以多写几个begin end 里面包括异常处理,这样来控制自治事务的执行;
    如果是并行的,这样是比较好的;
    如果 sth1 和sth2 之间有前后关系,建议还是放在一个块里面,这样一步出错也不会往下执行;
      

  7.   

    如果出现异常,跳入exception,否则向下执行
    do something 1; 
    commit; 
    do something 2; 
    <<here>>
    commit; 
    do something 3; 
    exception  
      when  others  then  
    GOTO here;
      rollback;