In 10g, if you are trying to make DDL changes on a busy object, you’re met with:
ORA-00054: resource busy and acquire with NOWAIT specified
If you google how to fix this, you're told to re-run the transaction, or find out what’s locking the object. If you're trying to make schema changes on a live system in a scripted/automated way, you don't want to interfere with production processes and you need to deal with re-running the transaction in an automated way. This is the solution:
DECLARE resource_busy EXCEPTION;
PRAGMA EXCEPTION_INIT(resource_busy, -54);
PROCEDURE try_change IS
BEGIN
dbms_lock.sleep(0.5);
EXECUTE IMMEDIATE 'alter table .....';
EXCEPTION WHEN resource_busy THEN try_change;
END;
BEGIN
try_change;
END;
/
Add new comment