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.

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 移动sim卡坏了怎么办 cpu和主板不兼容怎么办 主板与cpu不兼容怎么办 cpu跟主板不兼容怎么办 软件与电脑不兼容怎么办 win8系统无限重启怎么办 安装微信旧版本登录提示升级怎么办 手机软件与系统不兼容怎么办 下载旧版本微信闪退登陆不了怎么办 企业微信一直登录失败怎么办 360浏览器9.1经常卡死怎么办 手机版爱奇艺看电影屏幕变小怎么办 找不到旧版本米聊怎么办 苹果id被锁了怎么办 新浪微博支付宝解绑失败怎么办 阿里妈妈升级看不到引流人数怎么办 阿里妈妈账号被冻结怎么办 微博昵称到次数怎么办 五星好评之后忘记截图了怎么办 评价后忘了截图怎么办 好评率太低不能买东西了怎么办 淘宝评价被删了怎么办 淘宝店铺有流量没有成交怎么办 淘宝好评被删了怎么办 淘宝评论被系统删除怎么办 淘宝被商家删除评价怎么办 淘宝评价管理商家删除了怎么办 淘宝商家删除评价我该怎么办 我的评价隐藏了怎么办 淘宝把评论删了怎么办 淘宝虚假交易被删除评价怎么办 淘宝好评评错了怎么办 被淘宝骗了好评怎么办 美团好评被删了怎么办 卖家收到好评内容是差评怎么办 淘宝收货电话写错了怎么办 淘宝评价写错了怎么办 饿了么商家差评怎么办 淘宝不给补差价怎么办 淘宝顾客给差评怎么办 淘宝买家账号体检违规怎么办