首先,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的区别和使用的更多相关文章

  1. 【JAVA】FOR UPDATE 和 FOR UPDATE NOWAIT 区别 (转)

    1.for update 和 for update nowait 的区别:首先一点,如果只是select 的话,Oracle是不会加任何锁的,也就是Oracle对 select 读到的数据不会有任何限 ...

  2. [转]oracle for update和for update nowait的区别

    1概念小结:(针对以下引用区域内容) 1.1 普通select语句不加锁. 1.2 for update和for update nowait都试图将符合条件的数据加上行级锁.用于排斥其他针对这个表的写 ...

  3. Oracle 中 for update 和 for update nowait 的区别

    原文出处http://bijian1013.iteye.com/blog/1895412 一.for update 和 for update nowait 的区别 首先一点,如果只是select 的话 ...

  4. sql: oracle, for update和for update nowait的区别

    1. oracle for update和for update nowait的区别 http://www.cnblogs.com/quanweiru/archive/2012/11/09/276222 ...

  5. oracle for update和for update nowait(for update wait)的区别

    1.for update 和 for update nowait 的区别: 1.oracle 中执行select 操作读取数据不会有任何限制,当另外一个进程在修改表中的数据,但是并没有commit,所 ...

  6. oracle for update和for update nowait的区别 - 转

    1.for update 和 for update nowait 的区别: 首先一点,如果只是select 的话,Oracle是不会加任何锁的,也就是Oracle对 select 读到的数据不会有任何 ...

  7. oracle for update和for update nowait 的区别

    原文地址:http://www.cnblogs.com/quanweiru/archive/2012/11/09/2762223.html 1.for update 和 for update nowa ...

  8. Oracle 中for update和for update nowait的区别

    http://www.cnblogs.com/quanweiru/archive/2012/11/09/2762223.html 1.for update 和 for update nowait 的区 ...

  9. select for update和select for update wait和select for update nowait的区别

    CREATE TABLE "TEST6" ( "ID" ), "NAME" ), "AGE" ,), "SEX ...

随机推荐

  1. IE7和IE8出现的计算判断问题

    吸住底部菜单 IE7和IE8下会卡死的算法 ; } function fixedBar(){ var _height=$(this).height()+$(this).scrollTop(); var ...

  2. Top WAF

    http://blog.csdn.net/force_eagle/article/details/9396087

  3. 【HDOJ】3088 WORM

    状态压缩+BFS. /* 3088 */ #include <iostream> #include <cstdio> #include <cstring> #inc ...

  4. OpenCV 2.4.3在VS2010上的应用

    一.下载和安装:    1.OpenCV 2.4.3下载:http://www.opencv.org.cn/index.php/Download#Version_2.4.3    2.下载完成后,解压 ...

  5. Gold Balanced Lineup(哈希表)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10711   Accepted: 3182 Description Farm ...

  6. (转载)php curl_init函数用法

    (转载)http://blog.sina.com.cn/s/blog_640738130100tsig.html 使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所 ...

  7. 数学(欧拉函数):UVAOJ 11426 GCD - Extreme (II)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAgAElEQVR4nOzdPW7zvII/bG1gCi9gKq ...

  8. Java---类反射(2)---类反射加强

    经过前面的一篇博客,Java-类反射(1),相信大家对类反射有了一定的了解了. 下面来进行对类反射的加强,了解一下怎么通过类反射去new一个对象, 怎么通过类反射去访问其他类的方法. 怎么通过类反射去 ...

  9. 暴力求解——hdu 1799 循环多少次?

    Description   我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次OP运算,如 ...

  10. Python文件中文编码问题

    读写中文 需要读取utf-8编码的中文文件,先利用sublime text软件将它改成无DOM的编码,并且在第一行写: # encoding: utf-8 然后用以下代码: with codecs.o ...