Oracle Flashback Table
Ensure that the prerequisites described in Prerequisites for Flashback Table are met.
To use the Flashback Table feature on one or more tables, use the FLASHBACK TABLE SQL statement with a target time or SCN. You must have the following privileges to use the Flashback Table feature: You must have been granted the FLASHBACK ANY TABLE system privilege or you must have the FLASHBACK object privilege on the table. You must have READ or SELECT, INSERT, DELETE, and ALTER privileges on the table. To flash back a table to a restore point, you must have the SELECT ANY DICTIONARY or FLASHBACK ANY TABLE system privilege or the SELECT_CATALOG_ROLE role. For an object to be eligible to be flashed back, the following prerequisites must be met: The object must not be included the following categories: tables that are part of a cluster, materialized views, Advanced Queuing (AQ) tables, static data dictionary tables, system tables, remote tables, object tables, nested tables, or individual table partitions or subpartitions. The structure of the table must not have been changed between the current time and the target flashback time. The following Data Definition Language (DDL) operations change the structure of a table: upgrading, moving, or truncating a table; adding a constraint to a table, adding a table to a cluster; modifying or dropping a column; adding, dropping, merging, splitting, coalescing, or truncating a partition or subpartition (except adding a range partition). Row movement must be enabled on the table, which indicates that rowids change after the flashback occurs. This restriction exists because if rowids before the flashback were stored by the application, then there is no guarantee that the rowids correspond to the same rows after the flashback. If your application depends on rowids, then you cannot use Flashback Table. The undo data in the undo tablespace must extend far enough back in time to satisfy the flashback target time or SCN. The point to which you can perform Flashback Table is determined by the undo retention period, which is the minimal time for which undo data is kept before being recycled, and tablespace characteristics. The undo data contains information about data blocks before they were changed. The flashback operation uses undo to re-create the original data. To ensure that the undo information is retained for Flashback Table operations, Oracle suggests setting the UNDO_RETENTION parameter to 86400 seconds (24 hours) or greater for the undo tablespace.
Keeping Triggers Enabled During Flashback Table
By default, the database disables triggers on the affected table before performing a FLASHBACK TABLE
operation. After the operation, the database returns the triggers to the state they were in before the operation (enabled or disabled). To keep triggers enabled during the flashback of the table, add an ENABLE TRIGGERS
clause to the FLASHBACK TABLE
statement in Step 7.
For example, assume that at 17:00 an HR administrator discovers that an employee is missing from the hr.temp_employees
table. This employee was included in the table at 14:00, the last time the report was run. Therefore, someone accidentally deleted the record for this employee between 14:00 and 17:00. The HR administrator uses Flashback Table to return the table to its state at 14:00, respecting any triggers set on the hr.temp_employees
table, by using the SQL statement in the following example:
FLASHBACK TABLE hr.temp_employees TO TIMESTAMP TO_TIMESTAMP('2013-03-03 14:00:00' , 'YYYY-MM-DD HH:MI:SS') ENABLE TRIGGERS;