• Oracle Savepoint


    1.目的:

    Use the SAVEPOINT statement to identify a point in a transaction to which you can later roll back.

    使用检查点语句标识一个事务点以便在后面可以回滚。

    2. 预备知识:

     

    无。

    3.语法:

    Description of savepoint.gif follows

    SAVEPOINT savepoint ;

    4.下面来看示例:

    1)首先看一下员工表中Banda的工资

    SQL> select employee_id, last_name, salary from employees where last_name='Banda';

    EMPLOYEE_ID LAST_NAME                     SALARY
    ----------- ------------------------- ----------
            167 Banda                           6200

    2)我们来修改一下Banda的工资并创建检查点banda_sal:

    SQL> update employees
      2     set salary = 7000
      3     where last_name ='Banda';

    已更新 1 行。

    SQL> savepoint banda_sal;

    保存点已创建。

    3)再对Banda的工资做一次修改并创建检查点banda_sal2:

    SQL> update employees
      2     set salary = 8000
      3     where last_name ='Banda';

    已更新 1 行。

    SQL> savepoint banda_sal2;

    保存点已创建。

    SQL> select employee_id, last_name, salary from employees where last_name='Banda';

    EMPLOYEE_ID LAST_NAME                     SALARY
    ----------- ------------------------- ----------
            167 Banda                           8000

    4)下面进行回退操作,使回退到检查点banda_sal:

    SQL> rollback to savepoint banda_sal;

    回退已完成。

    SQL> select employee_id, last_name, salary from employees where last_name='Banda';

    EMPLOYEE_ID LAST_NAME                     SALARY
    ----------- ------------------------- ----------
            167 Banda                           7000

    5)下面进行提交操作,再进行回退操作:

    SQL> commit;

    提交完成。

    SQL> rollback to savepoint banda_sal2;
    rollback to savepoint banda_sal2
    *
    第 1 行出现错误:
    ORA-01086: 从未创建保存点 'BANDA_SAL2'

    5. 总结:

    1)通过创建检查点我们可以在事务提交前回退到任意已创建检查点的事务。

    2)检查点在事务提交后就不存在了,这点可以从示例中看出。

  • 相关阅读:
    Ext.grid.column.Column主要配置项及示例
    Ext.grid.Panel主要配置及示例
    EF Code First关系规则及配置
    ExtJS4系列目录
    EF Code First数据库连接配置
    ASP.NET MVC系列:ASP.NET MVC简介
    Ext JS下载及配置
    Ext.container.Viewport
    Ext.tab.Panel页签
    ASP.NET MVC系列:Controller/Action
  • 原文地址:https://www.cnblogs.com/toowang/p/3611429.html
Copyright © 2020-2023  润新知