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.
The FOR UPDATE SKIP LOCKED is documented here: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6