I think what actually happens to the rows selected with the FOR UPDATE option depends on the isolation level currently in effect.
If I run a query (with a FOR UPDATE) using CS isolation a row is only locked with U lock while the cursor is positioned on that row. After the last row is fetched by the internal cursor created for that dynamic SELECT statement no U locks remain in effect. Below are two snapshots; one is taken while the query runs:
Code:
List Of Locks
Lock Name = 0x00020C020AAA23110000000052
Lock Attributes = 0x00000000
Release Flags = 0x00000001
Lock Count = 1
Hold Count = 0
Lock Object Name = 178922257
Object Type = Row
Tablespace Name = USERSPACE1
Table Schema = XXX
Table Name = XXX
Mode = U
Lock Name = 0x00000001000000010001030056
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal V Lock
Mode = S
Lock Name = 0x94928D848F9F949E7B89505241
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal P Lock
Mode = S
Lock Name = 0x96A09A989DA09A7D8E8A6C7441
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal P Lock
Mode = S
Lock Name = 0x00020C02000000000000000054
Lock Attributes = 0x00000000
Release Flags = 0x00000001
Lock Count = 1
Hold Count = 0
Lock Object Name = 3074
Object Type = Table
Tablespace Name = USERSPACE1
Table Schema = XXX
Table Name = XXX
Mode = IX
the other after the last row has been retrieved:
Code:
List Of Locks
Lock Name = 0x94928D848F9F949E7B89505241
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal P Lock
Mode = S
Lock Name = 0x96A09A989DA09A7D8E8A6C7441
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal P Lock
Mode = S
If I run the same query using RR isolation the entire table is locked with a U lock and it remains in effect until the transaction is committed. Here's a snapshot taken while the query runs:
Code:
List Of Locks
Lock Name = 0x94928D848F9F949E7B89505241
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal P Lock
Mode = S
Lock Name = 0x96A09A989DA09A7D8E8A6C7441
Lock Attributes = 0x00000000
Release Flags = 0x40000000
Lock Count = 1
Hold Count = 0
Lock Object Name = 0
Object Type = Internal P Lock
Mode = S
Lock Name = 0x00020C02000000000000000054
Lock Attributes = 0x00000010
Release Flags = 0x40000002
Lock Count = 1
Hold Count = 0
Lock Object Name = 3074
Object Type = Table
Tablespace Name = USERSPACE1
Table Schema = XXX
Table Name = XXX
Mode = U