ORACLE PL/SQL:在 Oracle SQL Developer 中测试 SELECT FOR UPDATE
我们当前正在尝试实现 SELECT FOR UPDATE 来锁定行。如果我运行:
SELECT * FROM data where rowid = 'AAAQA5AAGAACNbEAA1' FOR UPDATE;
SELECT * FROM data where rowid = 'AAAQA5AAGAACNbEAA1' FOR UPDATE NOWAIT;
我在 ORACLE SQL Developer 中什么也没有得到。这不是应该给我一个错误吗?这与使用相同的用户 ID 有关系吗?
We are currently trying to implement a SELECT FOR UPDATE in order to lock rows. If I run:
SELECT * FROM data where rowid = 'AAAQA5AAGAACNbEAA1' FOR UPDATE;
SELECT * FROM data where rowid = 'AAAQA5AAGAACNbEAA1' FOR UPDATE NOWAIT;
I get nothing back in ORACLE SQL Developer. Isn't this supposed to throw me an error? Does this have something to do with using the same user id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“我什么也得不到”是什么意思?您的意思是两个查询都没有返回任何行吗?如果是这样,则意味着表中没有具有该 ROWID 的行。您的意思是第一个(或第二个)语句永远不会返回?如果是这样,会话将被阻塞,等待获取锁。
锁由会话持有。如果这两个语句在同一会话中运行,则第二个语句将成功,因为第一个语句已经获取了锁。如果第二条语句在恰好由同一用户打开的不同会话中运行,则应生成该行已被另一个会话锁定的异常。
What do you mean by "I get nothing back"? Do you mean that neither query returns any rows? If so, that implies that there are no rows in the table that have that ROWID. Do you mean that the first (or second) statement never returns? If so, the session is blocked waiting for the lock to be acquired.
Locks are held by sessions. If the two statements are run in the same session, the second statement will succeed because the the first statement already acquired the lock. If the second statement is run in a different session that happens to be opened by the same user, you should generate an exception that the row is already locked by another session.
您请求对已在该事务中锁定的表进行锁定。
您需要从不同的连接(即不同的事务)运行第二个 SELECT
You request a lock on a table that you have already locked in that transaction.
You need to run the second SELECT from a different connection (i.e. a different transaction)