Before we use Flashback Table, We must enable row movement on the table. because rowids will change after the flashback.
Example: Flashback the table back to previous time using SCN
Example: Flashback the table back to previous time using SCN
SQL> select count(*) from scott.test;Enable row movement:
COUNT(*)
----------
68781
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
1584494
SQL> delete from scott.test where rownum <= 50000; 50000 rows deleted. SQL> commit;
Commit complete.
SQL> select count(*) from scott.test;
COUNT(*)
----------
18781
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
1587106
SQL> alter table scott.test enable row movement;We can rewind the table back to previous time using timestamp:
Table altered.
SQL> FLASHBACK TABLE scott.test to scn 1584494;
Flashback complete.
SQL> select count(*) from scott.test;
COUNT(*)
----------
68781
SQL> alter table scott.test disable row movement;
Table altered.
SQL> alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';Nice feature...
Session altered.
SQL> select sysdate from dual;
SYSDATE
-------------------
2009/08/30 17:01:09
SQL> delete from scott.test ;
68781 rows deleted.
SQL> commit;
Commit complete.
SQL> select sysdate from dual;
SYSDATE
-------------------
2009/08/30 17:03:18
SQL> select count(*) from scott.test;
COUNT(*)
----------
0
SQL> alter table scott.test enable row movement;
Table altered.
SQL> flashback table scott.test to timestamp TO_TIMESTAMP('2009/08/30 17:01:09','YYYY/MM/DD HH24:MI:SS');
Flashback complete.
SQL> select count(*) from scott.test;
COUNT(*)
----------
68781
(Thank You Bradd Piontek commend, After check 10gR2, we can rewind the table back to previous time as well)
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
SQL> create table test tablespace users as select * from all_objects;
Table created.
SQL> select count(*) from test;
COUNT(*)
----------
42981
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
---------------------
8361904200781
SQL> delete from test ;
42981 rows deleted.
SQL> commit;
Commit complete.
SQL> select count(*) from test;
COUNT(*)
----------
0
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
---------------------
8361904200441
SQL> alter table test enable row movement;
Table altered.
SQL> FLASHBACK TABLE test to scn 8361904200781;
Flashback complete.
SQL> select count(*) from test;
COUNT(*)
----------
42981
