I have the following FOR LOOP in an PLSQL Block . I want to use a FOR UPDATE clause to lock the respective row. But running the code gives following exception back:
ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
I looked it up, but honestly I do not understand the explanations, so I can not solve that for now.
FOR l_rec IN (SELECT *
FROM (SELECT *
FROM my_table
WHERE status = 'NEW'
ORDER BY key_id)
WHERE ROWNUM <= i_max
FOR UPDATE)
LOOP
-- do work...
UPDATE my_table SET status = 'FINISHED' WHERE key_id = l_rec.key_id;
Could anybody give a comprehensive explanation of what is going on here and knwos how to solve that issue?
EDIR: Forgot to mention, my_table is no view, it is just a normal table.