Show TOC

Syntax documentationSELECT FOR UPDATE Statement Locate this document in the navigation structure

The SELECT ... FOR UPDATE statement retrieves columns from a uniquely specified row of database table and simultaneously set an update lock on the selected row. This statement is specific to Open SQL.

Note Note

In Open SQL the update lock is set on the row directly after execution of the statement.

End of the note.
Syntax

Syntax Syntax

  1. <select for update statement> ::= 
        SELECT ( ALL )? <select list> 
                     FROM <table reference> <where clause> 
                     FOR UPDATE ( OF <column reference list> )?
    
    <column reference list> ::= <column reference> ( ',' <column reference> )*.
    
End of the code.

Some semantic restrictions apply:

  • the FROM clause can contain only a single table

  • for all primary key columns of the table, the WHERE clause must contain <comparison predicate> with the comparison operator '='; all these comparison predicates must be combined by AND

  • the SELECT list must not contain set functions

Example

Syntax Syntax

  1. SELECT employee_name FROM employees WHERE employee_id = 123 FOR UPDATE
End of the code.

Example 1: The SELECT FOR UPDATE Statement. From the table employees a single row with the key value employee_id = 123 is selected. Simultaneously, an update lock is set on the selected row.