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 ...
随机推荐
- 常见的三种Web服务架构
常见的三种Web服务架构 转自http://www.cnblogs.com/bvbook/archive/2008/12/24/1360942.html 相互竞争的服务架构 The Competing ...
- cf B Inna and Candy Boxes
题意:输入n,然后输入n个数ai,再输入n个数bi,如果在1-ai中能找到两个数x,y,x和y可以相等,如果x+y=bi,答案加上x*y,否则减去1,让结果尽可能大,输出结果. #include &l ...
- iOS手写2048--基于Xcode7.1
闲着没事自己想了下,半天写出来了,没有美化,只是实现了基本的2048,被我改成了A.B.C.D.E: 没有游戏开发经验,完全基于uiview 和 一大堆逻辑计算,如果你有指针.链表的使用经验,应该会很 ...
- 【POJ】1816 Wild Words
DFS+字典树.题目数据很BT.注意控制DFS深度小于等于len.当'\0'时,还需判断末尾*.另外,当遇到*时,注意讨论情况. #include <iostream> #include ...
- 老毛桃U盘启动盘制作工具V20140501完美贡献版
老毛桃U盘启动盘制作工具V20140501完美贡献版 下载地址:http://down.laomaotao.net:90/LaoMaoTao_V2014zhuangji.exe 老毛桃U盘装系统综合教 ...
- 【REST API】
微信公众平台开发者文档 RESTful API 设计最佳实践 登录判断写去接口里 PUT 新建一个资源POST 更新一个资源GET 查看一个资源DELETE 删除一个资源
- ♫【jQuery】detach
Jquery empty() remove() detach() 方法的区别 <!DOCTYPE html> <html> <head> <meta char ...
- Single Number III——LeetCode
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- [已解决问题] An error occurred while automatically activating bundle com.android.ide.eclipse.adt
可以参见stackoverflow的解决方案:http://stackoverflow.com/questions/16974349/an-error-occurred-while-automatic ...
- poj1222
貌似又是一个矩阵图形的问题,看起来应该是不太容易,不管了先做做吧! 题目大意: 题目:灯光延伸出去(延长熄灯)?? 在一个扩展的游戏版本 熄灯,它是一个难题(或者谜)在一个5行每一行有6个按钮(实际是 ...