事务要么全部成功,要么全部失败
我想问一下,在一段DML语句中,我要怎么判断哪里出错或什么时候出错,然后可以回滚事务呢?比如有两条更新SQL语句,其中一条更新失败我就回滚,我要怎么知道它更新失败?顺便问一下,怎么查询出刚刚添加到表中的一条记录,不能依靠排序。

解决方案 »

  1.   

    举例:
    begin
     begin
       savepoint t1;
       update操作;
     end;
     exception
        when others then
        rollback to t1;
     begin
       savepoint t2;
       delete 操作;
     end;
     exception
        when others then
        rollback to t2;
    end;
      

  2.   

    exception
      when others then
    rollback;--可以回滚任何dml产生的错误。顺便问一下,怎么查询出刚刚添加到表中的一条记录,不能依靠排序。
    --可以表上建一个序列字段,根据到的最大的序列,就能得到新插入到表的记录