Friday 14 May 2021

Flashback table to before drop

flashback table helps us to restore table to before state in case of human or application error


SQL> select * from table1;


       SNO NAME                  SAL DOB             HIREDATE

---------- -------------- ---------- --------------- ---------------

         1 Jay                  2000 19850601.000000 20151111.000000


SQL> drop table table1;


Table dropped.


SQL> select * from table1;

select * from table1

              *

ERROR at line 1:

ORA-00942: table or view does not exist


Check recycle bin:

SQL> SELECT object_name, droptime FROM user_recyclebin  WHERE original_name = 'TABLE1';


OBJECT_NAME                        DROPTIME

-------------------------------   -------------------

BIN$5iiyOpVyZ6LgU6s4EKx1Iw==$0     2021-05-13:16:28:54


Restore table:

SQL> flashback table table1 to before drop;

Flashback complete.


SQL> select * from table1;

       SNO NAME                  SAL DOB             HIREDATE

---------- -------------- ---------- --------------- ---------------

         1 Jay                  2000 19850601.000000 20151111.000000



We can also flashback  table using scn , time stamp

FLASHBACK TABLE table1 TO SCN scn_value; 

FLASHBACK TABLE table1 TO TIMESTAMP TO_TIMESTAMP('Date', 'YYYY-MM-DD HH:MI:SS');

No comments:

Post a Comment