In this example, you rewind the hr.employees
table and its dependent tables to a previous point in time.
To perform the Flashback Table operation:
Use the following SQL query to determine the dependencies for the hr.employees
:
SELECT other.owner, other.table_name FROM sys.all_constraints this, sys.all_constraints other WHERE this.owner = 'HR' AND this.table_name = 'EMPLOYEES' AND this.r_owner = other.owner AND this.r_constraint_name = other.constraint_name AND this.constraint_type='R'; OWNER TABLE_NAME ------------------------------ ------------------------------ HR EMPLOYEES HR JOBS HR DEPARTMENTS
In this example, row movement must be enabled for the tables hr.employees
, hr.jobs
, and hr.departments
using the steps described in "Enabling Row Movement on a Table."
In this example, we assume that the rows were accidentally inserted 5 minutes ago. Therefore, you must rollback to a timestamp that is 5 minutes before the current time.
Note:
If you do not know the time at which the unwanted changes occurred, you can use the Oracle Flashback Version Query to review all recent changes to the target table. Use of this feature is beyond the scope of this documentation.
Use the following query to determine how long undo data is being retained:
SELECT NAME, VALUE/60 MINUTES_RETAINED FROM V$PARAMETER WHERE NAME = 'undo_retention'; NAME MINUTES_RETAINED --------------- ---------------- undo_retention 15
FLASHBACK TABLE
statement to perform a flashback operation for the required tables.
The following SQL statements return the tables hr.employees
, hr.jobs
, and hr.departments
to the specified time:
FLASHBACK TABLE hr.employees TO TIMESTAMP TO_TIMESTAMP('2012-03-27 09:30:00', 'YYYY-MM-DD HH:MI:SS'); FLASHBACK TABLE hr.jobs TO TIMESTAMP TO_TIMESTAMP('2012-03-27 09:30:00', 'YYYY-MM-DD HH:MI:SS'); FLASHBACK TABLE hr.departments TO TIMESTAMP TO_TIMESTAMP('2012-03-27 09:30:00', 'YYYY-MM-DD HH:MI:SS');