Hello,
we have cursor in package->procedure-> as below,
in declare part --
cursor cur1 is
select *
from abc
where load = v_load --- load and v_load are number;
for update of cust_no nowait;in begin part --
tabelle := stl.gtext('xyz', 'pr12345.cxx', 1); ---- 'cur1:open'
open cur1 ;
loop
tabelle := stl.gtext('xyz', 'pr12345.cxx', 2); -- 'cur1:fetch'
fetch cur1 into newrec;
exit when cur1%notfound;in past month few times we receive error in log file --
Fehler in xxxxxx(package).xxxxxxx(procedure) cur1:open ORA-00054: Ressource belegt und Anforderung mit NOWAIT angegeben oder Timeout abgelaufen
this is in German, which translate --
Fehler in xxxxxx(package).xxxxxxx(procedure) cur1:open ORA-00054: Resource occupied and request specified with NOWAIT or timeout expired
Can you please help on how to handle this error, or to avoid what needs to be done.
It means another session has locked the rows the query accesses.
You can see this by running:
create table t (
c1 int primary key, c2 int
);
insert into t values ( 1, 1 );
commit;
update t
set c2 = 9999
where c1 = 1;
Then in another session trying:
select * from t
where c1 = 1
for update nowait;
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
You'll keep getting this error in the second session until the first transaction commits or rolls back.
How exactly you address this depends on your logic for dealing with many people changing the same data at the same time.
Options include:
- Telling the end user "someone else is changing these data, please try again later"
- Removing nowait, so the second session waits (possibly a long time) for the first transaction to complete. Note this can lead to lost updates.
- Changing to for update wait N; where N is the number of seconds to wait for the first session to end
- Restructuring the application so concurrent changes are less likely
These all have various pros and cons, so the first step is to figure out why two sessions are trying to change the same rows at the same time. This will help inform your choice over what to do.