Oracle闪回查询恢复delete删除数据
1. 获取数据删除前的一个时间点或scn,如下:
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') time, to_char(dbms_flashback.get_system_change_number) scn from dual;
或者
SELECT current_scn, TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS')
FROM v$database;
2. 查询该时间点(或scn)的数据,如下:
select * from test as of timestamp to_date('2015-04-22 10:30:56','yyyy-mm-dd hh24:mi:ss');
或者
select * from t as of scn 1060174;
3. 将查询到的数据,新增到表中。也可用更直接的方法,如:
SQL> create table test1 as select * from test as of timestamp to_date('2015-04-22 10:30:56','yyyy-mm-dd hh24:mi:ss');
Table created.
SQL> select count(*) from test1;
COUNT(*)
----------
4985
insert into test select * from test1;
或者更为直接的方式(谨慎)
insert into t select * from t as of scn 1061279;
insert into t select * from test as of timestamp to_date('2013-4-26 09:00:00','yyyy-mm-dd hh24:mi:ss');
Falshback query查询的局限:
1. 不能Falshback到5天以前的数据。
2. 闪回查询无法恢复到表结构改变之前,因为闪回查询使用的是当前的数据字典。
3. 受到undo_retention参数的影响,对于undo_retention之前的数据,Flashback不保证能Flashback成功。
4. 对drop,truncate等不记录回滚的操作,不能恢复。
5. 普通用户使用dbms_flashback包,必须通过管理员授权。命令如下:
SQL>grant execute on dbms_flashback to scott;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22821701/viewspace-1593313/
,如需转载,请注明出处,否则将追究法律责任。