Skip to content

Background jobs regularly fail with '...object is locked by another user,' and there's a LOCK_SYS package plus Oracle's V$LOCK view that might help — is there a way to check for and handle this in PL/SQL, for example by postponing the job's execution instead of erroring out?

Answer

Rather than digging into V$LOCK directly, the simplest approach is to attempt to lock the specific row yourself with SELECT ... FOR UPDATE NOWAIT and catch the resulting Oracle exception if it's already locked. Define a PRAGMA EXCEPTION_INIT binding a named exception to Oracle error -54 (resource busy), attempt the FOR UPDATE NOWAIT lock inside a function, and return a simple true/false based on whether the exception was raised — this lets your calling code decide whether to proceed, retry, or postpone. This mirrors the same technique the standard IFS framework itself uses internally (in its own internal nowait-locking helper) to safely check whether a record is currently locked before acting on it.

← Browse Developer Studio, deployment, and upgrades questions