SELECT
id
FROM table_name tkn1,
(SELECT
id,
ROWNUM rnum
FROM table_name
WHERE
PROCS_DT is null
order by PRTY desc, CRET_DT) result
WHERE tkn1.id= result.id
AND result.rnum <= 10 FOR UPDATE OF tkn1.id SKIP LOCKED
Here is my problem. 2 threads are accessing this query at the same time
Thread 1 – Executes select and locks 10 rows ordered by descending priority and created date. Next I would update the procs_dt as todays date from a separate query..
Thread 2 – Before update of procs_dt or commit happens from thread 1 , this thread executes this query. My requirement is that the next 10 unlocked rows must be handed over to thread 2. But what really happens is the same set of locked rows comes out of the inner query since procs_dt is still null and yet to be updated by thread 1 and since skip locked is given in the outer query, all those 10 rows are skipped and no records are returned for thread 2 to process
This ultimately defeats my multi threading requirement.
How to fix this query? I tried adding the skip locked to the inner query. But oracle 11g doesn allow it.
Experts please help. I am using oracle 11g
I’d go with something like this :
A cursor to select the rows in order for update, and use the LIMIT clause to get the first ten available.
Actually, I’d firstly see whether processing ALL outstanding rows as a set would be better than multi-threading.
Then if I did decide that I needed some form of multi-threading, I’d look at pipelined functions with parallel enabled (assuming I was on Enterprise Edition).