Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle equivalent of ROWLOCK, UPDLOCK, READPAST query hints

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?

like image 357
Synesso Avatar asked Oct 15 '10 00:10

Synesso


1 Answers

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.

like image 148
APC Avatar answered Nov 09 '22 23:11

APC