根据ORACLE10G的特性,当我执行Drop Table或delete all时,Oracle都会把被删除的表或数据记录放到数据库回收站(Database Recyclebin)里。这样我们就可以用flashback table命令恢复被删除的表,语法:
Flashback table 表名 to before drop;
sql@kokooa>flashback table test003 to before drop;
Flashback complete.
sql@kokooa>select * from test003;
NAME STATE PERSON
---- ---------- ----------
A 1
A 2
A 1
A 1
B 2
B 2
6 rows selected.
update的表
sql@kokooa>flashback table a to timestamp to_timestamp('2009-11-09 11:00:00','yyyy-mm-dd hh24:mi:ss');
一般会报错:
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
只需要:
sql@kokooa>alter table a enable row movement;
Table altered.
就OK了
sql@kokooa>flashback table a to timestamp to_timestamp('2009-11-09 11:00:00','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
sql@kokooa>select * from a;
NAME NUM
-------------------- ----------
jim 90
tom 100
kate 220
lily 330
SQL>show parameter db_flashback_retention_target
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440
默认情况下,oracle会对提交的数据做 1440 分钟,也就是一天的“缓存”,因此一天之内的数据是有办法找回的。