27 October 2006

Oracle Flashback Table

You can "rollback" a table in a past time in Oracle.


Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as SYS


SQL> grant select on v_$database to hr;

Grant succeeded

SQL> con hr/hr;
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as hr


SQL> create table flassh(x number);

Table created


SQL> alter table flassh enable row movement;

Table altered

SQL> insert into flassh values(1);

1 row inserted


SQL> commit;

Commit complete

SQL> SELECT db.CURRENT_SCN FROM v$database db;

CURRENT_SCN
-----------
    786903
4

SQL> insert into flassh values(1111);

1 row inserted

SQL> commit;

Commit complete


SQL> flashback table flassh to scn 7869034;

Done

SQL> SELECT * FROM flassh;

         X
----------
         1


SQL> insert into flassh values(1111);

1 row inserted

SQL> commit;

Commit complete


SQL> SELECT * FROM flassh;

         X
----------
         1
      1111


SQL> update flassh set x = 5 where x = 1;

1 row updated

SQL> commit;

Commit complete

SQL> SELECT * FROM flassh;

         X
----------
         5
      1111


SQL> flashback table flassh to scn 7869034;

Done


SQL> SELECT * FROM flassh;

         X
----------
         1


SQL>

No comments: