When recompiling a function, procedure, or package, Toad and SQL*Plus hangs or comes back with the error: ORA-04021: timeout occurred while waiting to lock object.
Cause: The package was locked from the user in another session, the window was lost.
1. Reboot the server
or
2. Oracle's Metalink Fix:
a. Verify whether the package is locked by another user:
SELECT * FROM v$access WHERE object = '<package>';
If there a row is returned, the package is still locked.
b. Use the SID which is returned and check in v$session which session is
locking this package.
SELECT SID, SERIAL#, OSUSER, USERNAME FROM V$SESSION WHERE sid = '<SID>';
c. If the session still is shown, use:
ALTER SYSTEM KILL SESSION '<sid>, <serial#>';