把整个表闪回到过去的某个时刻:
确定要把表闪回到过去的哪个时刻
对你要闪回的表开启行迁移
闪回表语法:flashback table 表名 to 过去的时间点
重新收集统计信息
drop table scott.e purge ;
1. 建立scott.e表 和scott.emp一样
create table scott.e as select * from scott.emp;
2. 当前时间
select to_char(sysdate ,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2017-09-26 00:48:25
3. 执行3个事务
update scott.e set sal=0 ;
commit;
update scott.e set sal=1 ;
updated.
commit;
delete from scott.e ;
commit;
4. 查看
select * from scott.e;
no rows selected
把表闪回最原始的数据 也就是scott的工资为3000的时候
对闪回的表有权限:FLASHBACK ANY TABLE 或者FLASHBACK TABLE
ELECT, INSERT, DELETE, and ALTER
要闪回的表允许行迁移
5. 判断scott.e是否允许行迁移
SQL> select TABLE_NAME,ROW_MOVEMENT from dba_tables where table_name='E' and owner='SCOTT';
TABLE_NAME ROW_MOVE
------------------------------ --------
E DISABLED
6. 启动行迁移
alter table scott.e enable row movement ;
检查
SQL> select TABLE_NAME,ROW_MOVEMENT from dba_tables where table_name='E' and owner='SCOTT';
TABLE_NAME ROW_MOVE
------------------------------ --------
E ENABLED
7. 先对scott.e表示做版本查询 (所有事务时间列出)
select versions_xid, to_char(versions_starttime,'yyyy-mm-dd hh24:mi:ss'),VERSIONS_STARTSCN,versions_operation ,ename ,sal from scott.e VERSIONS BETWEEN TIMESTAMP minvalue and maxvalue where empno=7788;
VERSIONS_XID TO_CHAR(VERSIONS_ST VERSIONS_STARTSCN V ENAME SAL
---------------- ------------------- ----------------- - ---------- ----------
0A00000074020000 2017-09-26 00:48:57 1047284 D SCOTT 1
04001A0084020000 2017-09-26 00:48:48 1047279 U SCOTT 1
0800190025030000 2017-09-26 00:48:33 1047269 U SCOTT 0
SCOTT 3000
例如:要把所有的记录到最原始的工资2017-09-26 00:48:33 或者scn 1047269
8. 确认闪回点:闪回查询
select ename,sal from scott.e as of timestamp to_timestamp('2017-09-26 00:48:33','yyyy-mm-dd hh24:mi:ss') where empno =7788;
ENAME SAL
---------- ----------
SCOTT 3000
或者
SQL> select ename,sal from scott.e as of scn 1047268 where empno =7788;
ENAME SAL
---------- ----------
SCOTT 3000
9. 实施闪回表
flashback table scott.e to timestamp to_timestamp('2017-09-26 00:48:33','yyyy-mm-dd hh24:mi:ss');
或者
flashback table scott.e to scn 1047268 ;
10. 重新收集统计信息
exec dbms_stats.gather_table_stats('SCOTT','E');
注意:闪回表动作不能对系统表(sys用户的表)