Select for update row lock 2008-05-26 15:15:37
Category: Oracle
Select ... The syntax for the FOR UPDATE statement is the same as the SELECT statement, except that the for UPDATE [NOWAIT] clause is appended to the SELECT statement. The statement is used to lock a specific row, if there is a WHERE clause, which satisfies the where condition. When these rows are locked, other sessions can select the rows, but the rows cannot be changed or deleted until the statement's transaction is terminated by a commit statement or a ROLLBACK statement. 20.51, the upper left corner of the session with select ... The FOR UPDATE statement locks the row for deptno= ' 01 ' in the Department table, and the session in the upper-right corner indicates that no other session can continue to change the data on that row. Information from the lock in the OEM can be seen, Select ... The lock added for the FOR UPDATE statement is the same as the lock added by the UPDATE statement: a row-level exclusive lock (indicating that multiple transactions cannot operate on the same row at the same time), and a table-level row exclusive lock. Figure 20.51 Select ... The FOR UPDATE statement locks the line 20.52 that conforms to the where condition, and the session in the upper-left corner locks the row of deptno= ' 01 ' in the Department table with the UPDATE statement, and the session in the upper-right corner indicates that no other session can be used with select ... The FOR UPDATE statement continues to lock the row. Figure 20.52 Select ... The FOR UPDATE statement was blocked by another session by 20.53, and the session in the upper-left corner locked the row of deptno= ' 01 ' in the Department table with the UPDATE statement, and the session in the upper-right corner indicates that no other session can be used with select ... The for Update NOWAIT statement continues to lock the row and returns an error prompt that says "ORA-00054: The resource is busy, but specifies that the resource is fetched NOWAIT" without waiting for the lock to succeed. Figure 20.53 If the lock is unsuccessful, select ... The FOR UPDATE NOWAIT statement immediately returns an error message, and it can be seen that if you change the data only with the UPDATE statement, you may not be able to wait for it to be unlocked and not be answered, but if you precede it, use SELECT ... The FOR UPDATE NOWAIT statement is a tentative lock on the data that is about to be changed, and it can be understood by the error prompt to return, perhaps this is the meaning of the for update and nowait.
Select for Update row lock