Oracle中的select for update
来源:互联网 发布:log4j.xml配置显示sql 编辑:程序博客网 时间:2024/05/20 11:21
在select…for update之后,可以使用of子句选择对select的特定数据表进行加锁操作。默认情况下,不使用of子句表示在select所有的数据表中加锁。
select * from test for update; 会对table test进行加锁. 此时只允许当前的session对已经存在的数据进行更新. 但其它session仍可以进行insert的操作.
select * from Table1 a join Table2 b on a.pkid=b.pkid where a.pkid = 10 for update of a.pkid 只锁定Table1中满足条件的行, 这就是使用of子句的作用. 比较常用于多个表的操作.
加入for update之后,Oracle就要求启动一个新事务,尝试对数据进行加锁。如果当前已经被加锁,默认的行为必然是block等待。使用nowait子句的作用就是避免进行等待,当发现请求加锁资源被锁定未释放的时候,直接报错返回。如果不使用nowait或wait子句, 新的加锁请求会一直hang住, 直到原来的commit或rollback.
select * from test where a=2 for update nowait;
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
或者
select * from test where a=2 for update wait 3; 如果3秒内还是无法加锁则返回错误.
在一个session内可以多次进行select XX for update,然后只需要commit或rollback一次即可释放.
- Oracle中的select for update
- Oracle中的select for update
- oracle select ... for update
- Oracle的select for update
- oracle的select for update
- Oracle Select...for update作用
- oracle行锁 select for update
- oracle行锁 select for update
- oracle行锁 select for update
- 浅谈Oracle select for update
- mysql中的select * for update
- Mysql中的select * for update
- oracle-select for update nowait 与 select for update 差别
- Postgre中的 select for update 和 select for update nowait
- Oracle中select ... for update的用法
- 【Oracle】从select for update开始
- oracle 锁住select查询结果for update
- SELECT语句中的for update的用法
- Hello World 4
- xx项目代码规范与项目质量
- Hello World 5
- JQ也要面向对象~在JQ中扩展静态方法和实例方法
- Export runnable jar in Eclipse.
- Oracle中的select for update
- 猴子吃桃
- Hello World 6
- C语言二进制文件和文本文件的区别
- Hibernate读书笔记-----HQL查询
- 数学之路(2)-数据分析-R基础(16)
- poj 2096 Collecting Bugs
- 优秀的程序 vs. 糟糕的程序
- Java_集合_Arrays工具类