We have a procedure for setting a unique number to a contract appendice. If a user selects multiple appendices to assign a number to, this procedure is simultanously called for each one of them.
It works when called for a single appendice, but when called in parallel for multiple appendices, it fails with ORA-00060: deadlock detected while waiting for resource
Can this be solved somehow?
declare
cursor c_data is
select dcd.document_id
d.regnumbervalue
from D_CONTRACT_DATA dcd
inner join DOCUMENTS d on dcd.document_id = d.id
where dcd.contract_id = pi_contract_id
for update;
begin
-- log here: all calls reach here
for r_document in c_data loop
if r_document.document_id = pi_document_id then
po_numberVal := case
when r_document... > 0
then nvl(r_document..., 0) + 1
when pi_pref_regnumval is not null
then pi_pref_regnumval
else nvl(r_document...., 0) + 1
end;
update D_CONTRACT_DATA dcd
set dcd.regnumbervalue = po_numberVal
where dcd.document_id = pi_document_id;
exit;
end if;
end loop;
-- log here: only one or two calls reach here
end;