views:

56

answers:

1

In SQL Server I used the following hints inside queries:

  • rowlock (row level locking)
  • updlock (prevents dirty reads)
  • readpast (don't block waiting for a rowlock, go to the first unlocked row)

e.g.

select top 1 data from tablez with (rowlock,updlock,readpast);

Are there equivalent in-query hints for Oracle?

+3  A: 

The equivalent of ROWLOCK is the FOR UPDATE clause

select *
from emp
for update;

Since 11g Oracle has documented the SKIP LOCKED syntax which is the equivalent of READPAST:

select *
from emp
for update skip locked;

This syntax has worked for ages (it is fundamental to Advanced Queuing) but if it's not in the docs it's not supported,

There is no equivalent of UPDLOCK lock because Oracle flat out doesn't allow dirty reads. Find out more.

APC
Thank you very much. Are you sure about your last statement? It seems like FOR UPDATE is a replacement for UPDLOCK, whereas ROWLOCK is more about the granularity of the lock employed.
Synesso
There's no simple one-to-one relationship between the lock types. DML in Oracle is driven by row-level locks. There's no concept of shared read locks in Oracle as it uses a different consistency mechanism. Exclusive insert/update/delete locks are held on the data record itself. Oracle only uses table level locks to prevent concurrent DDL.
Gary