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 3786 星系探索
Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均有且仅有一个依赖星球.主星球 ...
- JAVA内置的观察者模式样本
DisplayElement.java public interface DisplayElement { public void display(); } CurrentConditionsDisp ...
- 使用SetWindowPos API函数移动窗口后,还需修改Delphi的属性值,以备下次使用,否则就会出问题(不是API不起作用,而是使用了错误的坐标值)
单独改变坐标的代码如下,可不断左移: procedure TForm1.Button1Click(Sender: TObject); begin SetWindowPos(panel1.Handle, ...
- c# 函数相关练习
1.输入一个正整数,求1!+2!+3!+...+n! 2.输入姓名,年龄,工作单位 我叫**,今年**岁了,现在在****工作 要求,在Main函数中接收这三个值 传到函数中打印 3.写一 ...
- .net ref关键字在引用类型上的使用
只接上干货. namespace ConsoleApplication1 { class Person { public string UserName { get; set; } } class P ...
- 【ZOJ】3430 Detect the Virus
动态建树MLE.模仿别人的代码模板各种原因wa后,终于AC. #include <iostream> #include <cstdio> #include <cstrin ...
- javascript 基础学习整理 二 之 html对象总结,参考W3C
Anchor 对象 更改一个链接的文本.URL 以及 target 使用 focus() 和 blur() 向超链接添加快捷键 Document 对象 使用 document.write() 向输出流 ...
- Piggy-Bank(完全背包)
/* http://acm.hdu.edu.cn/showproblem.php?pid=1114 完全背包问题 再判断背包能否装满 题意: 给出存空钱罐的重量以及装满时的重量 给出每种硬币的面值以及 ...
- ios中键值编码kvc和键值监听kvo的特性及详解
总结: kvc键值编码 1.就是在oc中可以对属性进行动态读写(以往都是自己赋值属性) 2. 如果方法属性的关键字和需要数据中的关键字相同的话 ...
- [转]Android实现计时与倒计时(限时抢购)的几种方法
在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但 ...