标签:

COMMIT statement is executed.MINVALUE and MAXVALUE resolve to the SCN or time stamp of the oldest and most recent data available, respectively
下面是一个比较典型的闪回版本查询
COLUMN versions_startscn FORMAT 99999999999999999COLUMN versions_starttime FORMAT A24COLUMN versions_endscn FORMAT 99999999999999999COLUMN versions_endtime FORMAT A24COLUMN versions_xid FORMAT A16COLUMN versions_operation FORMAT A1COLUMN description FORMAT A11SET LINESIZE 200SELECT versions_startscn,versions_starttime,versions_endscn,versions_endtime,versions_xid,versions_operation,last_name, salaryFROM personnelVERSIONS BETWEEN TIMESTAMPTO_TIMESTAMP(‘2007-03-21 19:30:00‘, ‘YYYY-MM-DD HH24:MI:SS‘)AND TO_TIMESTAMP(‘2007-03-22 04:30:00‘, ‘YYYY-MM-DD HH24:MI:SS‘)WHERE first_name = ‘Anthony‘;
也可以使用MINVALUE和MAXVALUE定界
SQL> SELECT versions_xid AS XID, versions_startscn AS START_SCN, versions_endscn AS END_SCN, versions_operation AS OPERATION, first_name FROM employees VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE AS OF SCN 5525300 WHERE employee_id = 111;
SQL> select versions_startscn startscn,versions_endscn endscn, versions_xid xid, versions_operation oper, employee_id empid, last_name name, salary sal from hr.employees versions between timestamp trunc(systimestamp) and systimestamp where employee_id = 124;
SQL> SELECT * FROM test1;ID DESCR---------- ------------------------------1 One2 Two3 ThreeSQL> SELECT current_scn, SCN_TO_TIMESTAMP(current_scn) FROM v$database;CURRENT_SCN SCN_TO_TIMESTAMP(CURRENT_SCN)----------- ---------------------------------------------------------------------------29006118 15-AUG-11 12.51.21.000000000 PMSQL> UPDATE test1 SET descr=‘The one‘ WHERE id=1;1 ROW updated.SQL> COMMIT;COMMIT complete.SQL> UPDATE test1 SET descr=‘The only one‘ WHERE id=1;1 ROW updated.SQL> COMMIT;COMMIT complete.SQL> SELECT current_scn, SCN_TO_TIMESTAMP(current_scn) FROM v$database;CURRENT_SCN SCN_TO_TIMESTAMP(CURRENT_SCN)----------- ---------------------------------------------------------------------------29006142 15-AUG-11 12.52.03.000000000 PM
Remark:
Please note the commit after each update to generate multiple transactions.
You can now see past figures:
SQL> SELECT versions_startscn, versions_starttime, versions_endscn, versions_endtime, versions_xid, versions_operation, id, descrFROM test1VERSIONS BETWEEN SCN 29006118 AND 29006142WHERE id = 1;VERSIONS_STARTSCN VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIME VERSIONS_XID V ID DESCR----------------- ------------------------ --------------- ------------------------ ---------------- - ---------- ------------------------------29006133 15-AUG-11 12.51.45 PM 0A001500B99F0000 U 1 The only one29006128 15-AUG-11 12.51.36 PM 29006133 15-AUG-11 12.51.45 PM 060017000A100000 U 1 The one29006128 15-AUG-11 12.51.36 PM 1 OneSQL> SELECT * FROM test1 AS OF scn 29006128;ID DESCR---------- ------------------------------1 The one2 Two3 ThreeSQL> SELECT * FROM test1 AS OF scn 29006118;ID DESCR---------- ------------------------------1 One2 Two3 ThreeSQL> SELECT * FROM test1;ID DESCR---------- ------------------------------1 The only one2 Two3 Three
Remark:
Same as DBMS_FLASHBACK package you may work with timestamp or SCN.
http://blog.yannickjaquier.com/oracle/flashback-technologies-by-examples.html#Flashback_Versions_Query
https://oracle-base.com/articles/10g/flashback-10g#flashback_version_query
http://www.oracle-dba-online.com/flash_back_features.htm
标签:
原文地址:http://www.cnblogs.com/haoxiaoyu/p/e6813e6a8d096dbb8822daf4c8dd3535.html