Suppose I have Oracle table books
store n books info with columns id
and title
. Some of the tuples are locked by SELECT ... FOR UPDATE
clause.
Suppose these rows whose id in (1, 2, 4, 5, 6, 9) are get locked.
Now I want to write a SQL to achieve that when execute it, return the next 2 records which are unlocked. And the SQL may be called by multiple process at same time.
That is to say, the first call will return id = 3 and id = 7 records; the second call will return id = 8 and id = 10 records.
I think SELECT ... FOR UPDATE SKIP LOCKED
would help, it auto skips rows which are locked and solved the multiple process call at same time problem. But how to achieve get next 2 records? I don't think rownum works, because I do not know which rows are locked.
Could anybody share your ideas? Thanks a lot!