Home > Database > Mysql Tutorial > Oracle savepoint介绍

Oracle savepoint介绍

WBOY
Release: 2016-06-07 17:17:07
Original
1228 people have browsed it

Oracle savepoint介绍,通过创建检查点我们可以在事务提交前回退到任意已创建检查点的事务。检查点在事务提交后就不存在了,这点

SAVEPOINT  由官方文档提供

1.目的:

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

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

2. 预备知识:

无。

3.语法:

 

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

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template