ITPub博客

首页 > 数据库 > 数据库开发技术 > doc上描述的关于for update产生的表锁的一点错误!

doc上描述的关于for update产生的表锁的一点错误!

原创 数据库开发技术 作者:warehouse 时间:2013-05-17 16:22:43 0 删除 编辑
doc上提到select....for update of 会产生row share表锁但实际上加的却是row exclusive类型的表锁,这个可能和版本有关,我测试是在10gR2下测试的。[@more@]SQL> lock table t1 in row share mode;

表已锁定。

SQL> SELECT TYPE ,LMODE,
2 decode(lmode ,0 , 'none',1,'null',2,'row share',
3 3,'row exclusive',4,'share',5,'share row exclusive',6,
4 'exclusive') lock_type
5 from v$lock
6 where type in ('TX','TM');

TY LMODE LOCK_TYPE
-- ---------- -------------------
TM 2 row share

SQL> rollback;

回退已完成。

SQL> select * from t1 for update;

ID NAME
---------- ----------
1 a
2 b
3 c

SQL> SELECT TYPE ,LMODE,
2 decode(lmode ,0 , 'none',1,'null',2,'row share',
3 3,'row exclusive',4,'share',5,'share row exclusive',6,
4 'exclusive') lock_type
5 from v$lock
6 where type in ('TX','TM');

TY LMODE LOCK_TYPE
-- ---------- -------------------
TM 3 row exclusive
TX 6 exclusive
--=========================================
doc上还说当表上存在share row exclusive table lock 时其他事务可以执行select with the FOR UPDATE clause,但事实上也不可以
A share row exclusive table lock held by a transaction allows other transactions to query or lock specific rows using SELECT with the FOR UPDATE clause, but not to update the table.
session1:
14:39:43 SQL> lock table t1 in share row exclusive mode;

表已锁定。

已用时间: 00: 00: 00.00
14:48:43 SQL>
session2:
SQL> select *from t1 for update;

一直等待!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/19602/viewspace-1060513/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-12-07

  • 博文量
    717
  • 访问量
    5366307