Wednesday, January 28, 2026

How to recover table from flashback after truncate table in Oracle

 Tables dropped by Truncate TABLE can be restored using TO_TIMESTAMP and TO_SCN function.

Check if Flashback Database is enabled

SELECT flashback_on FROM v$database;

If result = YES, you can use flashback database.

Note: By default triggers is disable during the flashback recovery.

Following are the steps involved in flashback table with SCN or TIMESTAMP.

a. Enable the row movement for the table.

ALTER TABLE TEST ENABLE ROW MOVEMENT;

b. Flashback the table to SCN or timestamp.

FLASHBACK TABLE TEST TO SCN <scn_number>;
OR
FLASHBACK TABLE TEST TO TIMESTAMP TO_TIMESTAMP('2026-01-26 19:00:00','YYYY-MM-DD HH24:MI:SS');

Post‑Steps:

Verify the data:

SELECT COUNT(*) FROM TEST;

Disable the row movement:

ALTER TABLE TEST DISABLE ROW MOVEMENT;

Recompile the dependent object if they are invalid:

SELECT object_name, status 
FROM user_objects 
WHERE object_type IN ('VIEW','TRIGGER') AND status <> 'VALID';

-- Compile command for objects:
ALTER VIEW my_view COMPILE;
ALTER TRIGGER my_trigger COMPILE;
ALTER PROCEDURE my_procedure COMPILE;
ALTER FUNCTION my_function COMPLILE;

No comments:

Post a Comment