闪回版本查询(
Flashback Version Query
)是针对指定对象在规定时间段(SCN)内变化的所有情况。
语法:
SELECT column_name[,column_name,...]
FROM table_name
VERSIONS BETWEEN [SCN|timestamp] [expr|minvalue]
AND [epxr|maxvalue];
一、查询当前empno为7369的sal值为800
SCOTT@ORA10G>set time on
14:41:04 SCOTT@ORA10G>select ename,job,sal from emp where empno=7369;
ENAME JOB SAL
---------- --------- ----------
SMITH CLERK 800
14:41:16 SCOTT@ORA10G>
二、对 sal 值更新三次,每次增加200
14:41:17 SCOTT@ORA10G>update emp set sal=sal+200 where empno=7369;
1 row updated.
14:41:25 SCOTT@ORA10G>commit;
Commit complete.
14:41:32 SCOTT@ORA10G>update emp set sal=sal+200 where empno=7369;
1 row updated.
14:41:49 SCOTT@ORA10G>commit;
Commit complete.
14:41:51 SCOTT@ORA10G>update emp set sal=sal+200 where empno=7369;
1 row updated.
14:42:02 SCOTT@ORA10G>commit;
Commit complete.
14:42:04 SCOTT@ORA10G>
三、
查询更新后的最终值
14:42:05 SCOTT@ORA10G>select ename,job,sal from emp where empno=7369;
ENAME JOB SAL
---------- --------- ----------
SMITH CLERK 1400
14:42:10 SCOTT@ORA10G>
四、通过事务查询可以清晰的看到在指定时间范围内的各个版本信息
14:44:33 SCOTT@ORA10G>select to_char(versions_starttime,'yyyy-mm-dd hh24:mi:ss') as starttime,versions_xid,ename,job,sal from emp versions between timestamp to_date('20121011 14:41:00','yyyymmdd hh24:mi:ss') and sysdate where empno=7369;
STARTTIME VERSIONS_XID ENAME JOB SAL
------------------- ---------------- ---------- --------- ----------
2012-10-11 14:42:01 0100080039010000 SMITH CLERK 1400
2012-10-11 14:41:49 02002D0058010000 SMITH CLERK 1200
2012-10-11 14:41:31 08000A0056010000 SMITH CLERK 1000
SMITH CLERK 800
14:44:35 SCOTT@ORA10G>
五、小结
通过上面的测试,我们会清晰的发现,数据更新的各个版本。
另:
闪回版本查询所有伪列:
VERSIONS_STARTSCN:该记录操作时的起始SCN;
VERSIONS_ENDSCN:该记录修改时的终止SCN;
VERSIONS_STARTTIME:该记录操作时的开始时间;
VERSIONS_ENDTIME:该记录操作的结束时间;
VERSIONS_OPERATION:操作类型(I表示insert,D表示delete,U表示update);
VERSIONS_XID:操作的事务ID;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/685769/viewspace-749356/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/685769/viewspace-749356/