1、Flashback table是指闪回table对象到某一位置,主要用于恢复数据,它是通过undo tablespace来实现数据的回退功能,命令如下:
SQL>flashback table table_name to scn|timestamp
针对flashback table,table有一参数row movement,当启动闪回,则需设置为enable,反之设置为disable,默认值disable,用户可在user_tables(all_tables,dba_tables)中查询。
row movement设置命令如下:
SQL>alter table table_name enable row movement;
SQL>alter table table_name disable row movement;
2、Flashback table实例
⑴scn
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
9094977
另外一种序号查询的方法:
SQL> select dbms_flashback.get_system_change_number from dual;
需注意的是每经过一次查询,SCN号的值都会不同。
SQL> delete from dept;
4 rows deleted.
SQL> commit;
Commit complete.
SQL> flashback table dept to scn 9094960
2 ;
flashback table dept to scn 9094960
*
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
Flashback table只有在该表开启row movement时才有效
SQL> alter table dept enable row movement;
Table altered.
SQL> flashback table dept to scn 9094960;
Flashback complete.
Flashback table可以同时支持多个表,多表之间以逗号隔开即可,同时Flashback table闪回多表时,要么全部成功,要么全部失败。
SQL> select * from dept;
DEPT_ID DEPT_NAME
---------- --------------------
1 产品一部
2 产品二部
3 产品三部
4 产品四部
⑵timestamp
SQL> delete from dept;
4 rows deleted.
SQL> commit;
Commit complete.
SQL> flashback table dept to timestamp systimestamp - interval '10' minute;
Flashback complete.
SQL> select * from dept;
DEPT_ID DEPT_NAME
---------- --------------------
1 产品一部
2 产品二部
3 产品三部
4 产品四部
3、Flashback table注意事项
⑴ sys用户是不支持闪回
⑵ undo tablespace闪回需要注意ddl操作的影响,比如drop/modify列等操作会影响flashback table的恢复