闪回版本查询
1. 创建测试案例
sqlplus / as sysdba
scott@ORCL> select * from SCOTT.emp where sal=1300;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ------------------- ---------- ---------- ----------
7934 AAA CLERK 7782 1982-01-23 00:00:00 1300 10
scott@ORCL> update SCOTT.emp set empno=7910 ,ename='ABC' where SAL=1300;
1 row updated.
scott@ORCL> commit;
Commit complete.
scott@ORCL> select * from SCOTT.emp where sal=1300;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ------------------- ---------- ---------- ----------
7910 ABC CLERK 7782 1982-01-23 00:00:00 1300 10
2. 闪回版本查询
SQLPLUS / AS SYSDBA
COL VERSIONS_STARTTIME FOR A25
COL VERSIONS_ENDTIME FOR A25
SELECT versions_startscn,
versions_starttime,
versions_endscn,
versions_endtime,
versions_xid,
versions_operation,
empno,
ename
FROM scott.emp VERSIONS BETWEEN TIMESTAMP SYSDATE - 5 / 1440 AND SYSDATE --时间注意调整
WHERE sal = 1300;
VERSIONS_STARTSCN VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIME VERSIONS_XID VE EMPNO ENAME
----------------- ------------------------- --------------- ------------------------- ---------------- -- ---------- --------------------
1850518 26-JUN-19 06.57.40 AM 09000000FD040000 U 7910 ABC
1850518 26-JUN-19 06.57.40 AM 7934 AAA 7934 AAA
3. 闪回表到历史版本
SQLPLUS / AS SYSDBA
ALTER TABLE SCOTT.EMP ENABLE ROW MOVEMENT;
FLASHBACK TABLE SCOTT.EMP TO SCN 1850517;
SELECT * FROM SCOTT.EMP WHERE SAL=1300;
--执行结果
sys@ORCL> ALTER TABLE SCOTT.EMP ENABLE ROW MOVEMENT;
Table altered.
sys@ORCL> FLASHBACK TABLE SCOTT.EMP TO SCN 1850517; --注意这里的SCN和前面查询的SCN
Flashback complete.
sys@ORCL> SELECT * FROM SCOTT.EMP WHERE SAL=1300;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ------------------- ---------- ---------- ----------
7934 AAA CLERK 7782 1982-01-23 00:00:00 1300 10
可见数据已经恢复到指定版本
参考
【诗檀学院】ORACLE 11g OCM考试学习材料-手动实操课程