Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORACLE PL/SQL: Testing SELECT FOR UPDATE in Oracle SQL Developer

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?

like image 796
jlrolin Avatar asked Aug 29 '26 18:08

jlrolin


1 Answers

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.

like image 190
Justin Cave Avatar answered Sep 01 '26 06:09

Justin Cave