Update cursors

An update cursor is a special kind of cursor that applications can use when the row might potentially be updated. To use an update cursor, execute SELECT FOR UPDATE in your application. Update cursors use promotable locks; that is, the database server places an update lock (meaning other users can still view the row) when the application fetches the row, but the lock is changed to an exclusive lock when the application updates the row using an update cursor and UPDATE...WHERE CURRENT OF.

The advantage of using an update cursor is that you can view the row with the confidence that other users cannot change it or view it with an update cursor while you are viewing it and before you update it.
Tip: In an ANSI-compliant database, update cursors are unnecessary because any select cursor behaves the same as an update cursor.
The pseudocode in the following figure shows when the database server places and releases locks with a cursor.
Figure 1. Locks Placed for Update
begin figure description - This figure is described in the surrounding text. - end figure description

Copyright© 2020 HCL Technologies Limited