Using Flashback to return Past States
Using Flashback to return Past States.
Last updated:
Warning: Review and test in a non-production environment before running.
-- Based on: "Oracle Flash Back Query Explained with Example", oracle-dba-online.com – https://www.oracle-dba-online.com/flash_back_features.htm
-----------------------------------------------------------------------------------------------------------------------
-- Using Flashback Table to return Table to Past States.
-----------------------------------------------------------------------------------------------------------------------
-- Row movement must be enabled on the table for which you are issuing the FLASHBACK TABLE statement.
-- You can enable row movement with the following SQL statement:
ALTER TABLE emp ENABLE ROW MOVEMENT;
-- The following example performs a FLASHBACK TABLE operation the table emp
FLASHBACK TABLE emp TO TIMESTAMP TO_TIMESTAMP('2007-06-19 09:30:00', 'YYYY-MM-DD HH24:MI:SS');
/*
Example:-
At 17:00 an HR administrator discovers that an employee "JOHN" is missing from the EMPLOYEE table.
This employee was present at 14:00, the last time she ran a report.
Someone accidentally deleted the record for "JOHN" between 14:00 and the present time.
She uses Flashback Table to return the table to its state at 14:00, as shown in this example:
*/
FLASHBACK TABLE EMPLOYEES TO TIMESTAMP
TO_TIMESTAMP('2007-06-21 14:00:00','YYYY-MM-DD HH:MI:SS')
ENABLE TRIGGERS;
-- IMPORTENT
-- You have to give ENABLE TRIGGERS option otherwise, by default all database triggers on the table will be disabled.