for update和for update nowait的区别和使用
首先,for update 和for update nowait 是对操作的数据行进行加锁,在事务提交前防止其他操作对数据的修改。
for update 和for update nowait主要区别在于是否等待,如果不加nowait,在执行select时就会报错,如果加了nowait,在执行select时就会等待,直至锁被释放。
首先我们使用两个sql:
1.select * from HH t where id='1' for update
2.select * from HH t where id ='1' for update nowait
sql1在pl/sql中执行,sql2在ob12中执行(在pl/sql或ob12中开两个窗口执行不行,现在我也不知道为什么):
执行sql1后查询出正确信息,在执行sql2,出现错误信息“ORA-00054: 资源正忙, 但指定以 NOWAIT 方式获取资源, 或者超时失效”。这是因为执行sql1时对改行的数据加了锁,其他操作是不能访问改行的。当我们在sql1后执行commit后,sql2就能显示正确的数据。
将sql2换成for update 按上面得步骤执行,sql2会一直等待锁得释放不会,直至sql1后commit,sql2就能查询出数据;
这里还有 for update wait n (n是时间,单位:秒),即会等待n秒,n秒之后数据还是锁住的话就会报上面提到的错误;
其实for update 就是为了防止在查询数据的时候对数据进行修改,比如有以下两个sql:
sql1:select * from HH t where id='1' for update
sql2:update HH set name='张三' where id = '1'
当我们执行sql1后,在执行sql2,sql2就会一直等待sql1将锁释放后才能执行,这样在查询的时候就不会出行数据改变,在sql1后执行commit,sql2就会自动执行了。
for update和for update nowait的区别和使用的更多相关文章
- 【JAVA】FOR UPDATE 和 FOR UPDATE NOWAIT 区别 (转)
1.for update 和 for update nowait 的区别:首先一点,如果只是select 的话,Oracle是不会加任何锁的,也就是Oracle对 select 读到的数据不会有任何限 ...
- [转]oracle for update和for update nowait的区别
1概念小结:(针对以下引用区域内容) 1.1 普通select语句不加锁. 1.2 for update和for update nowait都试图将符合条件的数据加上行级锁.用于排斥其他针对这个表的写 ...
- Oracle 中 for update 和 for update nowait 的区别
原文出处http://bijian1013.iteye.com/blog/1895412 一.for update 和 for update nowait 的区别 首先一点,如果只是select 的话 ...
- sql: oracle, for update和for update nowait的区别
1. oracle for update和for update nowait的区别 http://www.cnblogs.com/quanweiru/archive/2012/11/09/276222 ...
- oracle for update和for update nowait(for update wait)的区别
1.for update 和 for update nowait 的区别: 1.oracle 中执行select 操作读取数据不会有任何限制,当另外一个进程在修改表中的数据,但是并没有commit,所 ...
- oracle for update和for update nowait的区别 - 转
1.for update 和 for update nowait 的区别: 首先一点,如果只是select 的话,Oracle是不会加任何锁的,也就是Oracle对 select 读到的数据不会有任何 ...
- oracle for update和for update nowait 的区别
原文地址:http://www.cnblogs.com/quanweiru/archive/2012/11/09/2762223.html 1.for update 和 for update nowa ...
- Oracle 中for update和for update nowait的区别
http://www.cnblogs.com/quanweiru/archive/2012/11/09/2762223.html 1.for update 和 for update nowait 的区 ...
- select for update和select for update wait和select for update nowait的区别
CREATE TABLE "TEST6" ( "ID" ), "NAME" ), "AGE" ,), "SEX ...
随机推荐
- BZOJ 1035 Risk
Description 经过连续若干年的推广,Risk这个游戏已经风靡全国,成为大众喜闻乐见的重要娱乐方式.Risk这个游戏可以理解为一种简易的策略游戏,游戏者的目的是占领所有的土地.由于游戏规则的规 ...
- java 垃圾回收机制 引用类型
Java语言的一个重要特性是引入了自动的内存管理机制,使得开发人员不用自己来管理应用中的内存.C/C++开发人员需要通过malloc/free 和new/delete等函数来显式的分配和释放内存.这对 ...
- JavaScript的应用
DOM, BOM, XMLHttpRequest, Framework, Tool (Functionality) Performance (Caching, Combine, Minify, JSL ...
- 我的HttpClients工具
import java.io.IOException; import javax.ws.rs.core.MediaType; import org.apache.commons.httpclient. ...
- linux 发布 qt(更新ld命令的路径依赖)
PATH 错误解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such ...
- Java 8 中的 Streams API 详解
为什么需要 Stream Stream 作为 Java 8 的一大亮点,它与 java.io 包里的 InputStream 和 OutputStream 是完全不同的概念.它也不同于 StAX 对 ...
- Android 批量上传sd卡图片
最近手头上需要批量上传一些保存到SD卡图片由于简单,过于忘记,写在博客中吧!同时也希望能帮到大家! 一 . 以下是一个Service类 package cn.com.service; import j ...
- C#程序注销、重启、关机和锁定电脑
一:截图 二:源代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- document.getElementById的简便方式
封装自己的元素获取方法,使元素获取变得简便 注意:1.应该要防止定义的被重写,可将同名的重新定义 2.可将封装的对象置为全局对象,方便使用 通过id查找单个元素 封装方式: //通过id查找单个元 ...
- Happy Number——LeetCode
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...