Queries Taking Too Much Time Due To Row and Table Locking In Oracle

  • Post author:
  • Post category:SQL
  • Reading time:2 mins read
You are trying to update particular rows in a table in Oracle and the statement taking too much time and after some time you get the error ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired.

After getting this error you identified the problem, to follow Oracle best practices for application development, use the NOWAIT clause and minimize the use of LOCK statements unless the application requires it. When a DML statement runs, the NOWAIT clause returns immediately if there is already a lock on the resource you require for the DML statement.

To avoid the wait during the UPDATE attempt, use the NOWAIT clause in a SELECT before the UPDATE statement in all sessions, as follows:

select * from employees e
where employee_id = 101
for update of salary nowait

If another session already has the row locked, you will receive this error message:

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.