How to recover a lost PACKAGE or PACKAGE BODY in Oracle using flash back memory

 Here is the correct and simplest way to restore an Oracle PACKAGE / PACKAGE BODY using Flashback features.

Oracle does not flashback individual objects directly — but you can restore them with the following supported methods.


Restore Package from Oracle FLASHBACK QUERY (Best & Easiest)

If the package existed earlier and you want the old version:

Step 1 — Query old source using flashback timestamp

SELECT text
FROM dba_source AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '2' HOUR)
WHERE name = '<PACKAGE_NAME>'
AND type = 'PACKAGE'
ORDER BY line;

For package body:

SELECT text
FROM dba_source AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '2' HOUR)
WHERE name = '<PACKAGE_NAME>'
AND type = 'PACKAGE BODY'
ORDER BY line;

Step 2 — Copy the output & recreate

CREATE OR REPLACE PACKAGE package_name AS
   ...
END;
/

CREATE OR REPLACE PACKAGE BODY package_name AS
   ...
END;
/

✔ Works if the package existed in the past and UNDO retention still keeps its source.
✔ No DBA involvement needed.


Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post