Cannot find official Oracle doc for cursor+ select for update skip locked

61 Views Asked by At

I'm using Oracle 19c.

In a concurrent environment, when I want to lock a single row I do the following

DECLARE
CURSOR cur IS
  SELECT id, name
    FROM sample
    ORDER BY id ASC
    FOR UPDATE SKIP LOCKED;
cur_record cur%ROWTYPE;
BEGIN
  OPEN cur;
  FETCH cur INTO cur_record;
  CLOSE cur;
  -- do some work with cur_record
END;

Please note that it does not limit rows (e.g. rownum) when declaring CURSOR. The row is locked on demand when the FETCH is executed.

I tested and it works as expected.

What I would like to know is if there is any official Oracle documentation, article or specification that indicates/back the following statement:

When I have a cursor with select for update skip locked then the records are locked on demand every time I do fetch.

2

There are 2 best solutions below

1
BobC On
0
Martins On

I have not found detailed documentation about SKIP locked.

We have had some difficulties with SKIP locked as sometimes too many rows got skipped/locked. One of explanations is here, that there could be block level locks in place: https://markjbobak.wordpress.com/2010/04/06/unintended-consequences/