Learn how to use the Oracle/PLSQL SELECT FOR UPDATE statement with syntax and examples.
The SELECT FOR UPDATE statement allows you to lock the records in the cursor result set. You are not required to make changes to the records in order to use this statement. The record locks are released when the next commit or rollback statement is issued.
The syntax for the SELECT FOR UPDATE statement in Oracle/PLSQL is:
CURSOR cursor_name IS select_statement FOR UPDATE [OF column_list] [NOWAIT];
cursor_name is the name of the cursor.
select_statement is a SELECT statement that will populate your cursor result set.
column_list are the columns in the cursor result set that you wish to update.
NOWAIT is optional. The cursor does not wait for resources.
For example, you could use the SELECT FOR UPDATE statement as follows:
CURSOR c1 IS SELECT course_number, instructor FROM courses_tbl FOR UPDATE OF instructor;
If you plan on updating or deleting records that have been referenced by a SELECT FOR UPDATE statement, you can use the WHERE CURRENT OF statement.