Oracle事务概念
来源:互联网 发布:物业管理收费软件app 编辑:程序博客网 时间:2024/05/17 04:54
本文参考了官网http://docs.oracle.com/cd/B28359_01/server.111/b28318/transact.htm 必看!
这篇文章包含了一些更细节的描述:http://docs.oracle.com/cd/E25054_01/server.1111/e25789/transact.htm#i974
事务的开始:
A transaction in Oracle Database begins when the first executable SQL statement is encountered. An executable SQL statement is a SQL statement that generates calls to an instance, including DML and DDL statements.
When a transaction begins, Oracle Database assigns the transaction to an available undo tablespace to record the rollback entries for the new transaction.用户也可以指定使用的回滚表空间。
事务的结束:
A transaction ends when any of the following occurs:
1, A user issues a COMMIT or ROLLBACK statement without a SAVEPOINT clause. 这里注意回滚到某个savepoint本身并不会结束当前事务,而是处于挂起的状态。
2, A user runs a DDL statement such as CREATE, DROP, RENAME, or ALTER. If the current transaction contains any DML statements, Oracle Database first commits the transaction, and then runs and commits the DDL statement as a new, single statement transaction. 因此DDL不能作为事务的一部分,同时用户也无法控制是否回滚DDL。
3, A user disconnects from Oracle Database. The current transaction is committed.
4, A user process terminates abnormally. The current transaction is rolled back.
Oracle不能像SQL Server那样显式的开始一个事务,也不能嵌套事务。
回滚到Savepoint:
When a transaction is rolled back to a savepoint, the following occurs:
1, Oracle Database rolls back only the statements run after the savepoint.
2, Oracle Database preserves the specified savepoint, but all savepoints that were established after the specified one are lost.
3, Oracle Database releases all table and row locks acquired since that savepoint but retains all data locks acquired previous to the savepoint.
The transaction remains active and can be continued.
因此回滚到savepoint之后,savepoint之后的DML被撤销,savepoint之前的DML不会被撤销,但也没有被commmit,当前事务挂起。因此用户还可以继续输入其他DML以及commit等语句。如果用户没有进一步的行为,则会被事务结束条件的3,4点结束。
如果是存储过程等代码,事务如何结束则和session如何结束相关。总的来说同样适用于事务结束条件的3,4点。
if there is no commit in the procedure, the transaction will be ended by the session that calls it; any locks will be held until the session issues a commit (or rollback). If it doesn't ever explicitly do so then the session will implicitly perform a commit or rollback when it ends, depending on how it is terminated. The transaction may exist before the procedure call to. The procedure is one statement within the transaction.
Statement-Level Rollback
If at any time during execution a SQL statement causes an error, all effects of the statement are rolled back. The effect of the rollback is as if that statement had never been run. This operation is a statement-level rollback.
Errors discovered during SQL statement execution cause statement-level rollbacks. An example of such an error is attempting to insert a duplicate value in a primary key. Single SQL statements involved in a deadlock (competition for the same data) can also cause a statement-level rollback. Errors discovered during SQL statement parsing, such as a syntax error, have not yet been run, so they do not cause a statement-level rollback.
A SQL statement that fails causes the loss only of any work it would have performed itself. It does not cause the loss of any work that preceded it in the current transaction. if the statement raises an unhandled exception, the host environment (such as SQL*Plus) determines what is rolled back.
- Oracle事务概念
- oracle 事务概念
- Oracle学习笔记20150830事务的概念
- oracle数据库事务及隔离级别的一些概念
- SQL事务概念
- SQL 事务的概念
- 和事务相关概念
- 事务隔离级别概念
- 事务的概念
- 事务--概念复习
- 事务的概念
- SQL事务概念
- 事务的概念
- JAVA事务的概念
- JAVA事务的概念
- 事务概念简述
- JDBC事务相关概念
- 事务的概念
- 原生JavaScript实现列表/表格的增删查改
- 轮播图片切换(函数传参)
- 关于android动态切换app主题颜色方案
- 复杂的MVP
- Gulp介绍与Hexo优化
- Oracle事务概念
- maven中snapshot快照库和release发布库的区别和作用
- IOS Masonry介绍与使用实践:快速上手Autolayout
- Ubuntu Android Studio 报错unable to run mksdcard sdk
- 量子计算的能够破解RSA加密吗?
- c++实验3-项目1--个人所得税计算器
- Android开发之EditText属性详解
- c++第三次实验(个人所得税计算器)
- C++实验3——个人所得税计算器