zoukankan      html  css  js  c++  java
  • 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)检查点在事务提交后就不存在了,这点可以从示例中看出。

  • 相关阅读:
    poj3181(Dollar Dayz)
    poj3666(Making the Grade)
    poj2392(Space Elevator)
    hdu5288(OO’s Sequence)
    hdu5289(Assignment)
    快学scala
    Spark Checkpointing
    Spark Performance Tuning (性能调优)
    Spark Memory Tuning (内存调优)
    Sparkstreaming and Kafka
  • 原文地址:https://www.cnblogs.com/toowang/p/3611429.html
Copyright © 2011-2022 走看看