分类: Oracle
2008-07-30 15:04:47
不需要设置,立即识别对行的所有更改
在 Oracle9i Database 中,我们看到它推出了以闪回查询形式表示的“时间机器”。该特性允许 DBA 看到特定时间的列值,只要在还原段中提供该数据块此前镜像的拷贝即可。但是,闪回查询只提供某时刻数据的固定快照,而不是在两个时间点之间被更改数据的运行状态表示。某些应用程序,如涉及到外币管理的应用程序,可能需要了解一段时期内数值数据的变化,而不仅仅是两个时间点的数值。由于闪回版本查询特性, 能够更方便高效地执行该任务。
查询对表的更改
SQL> desc rates Name Null?Type ----------------- -------- ------------ CURRENCY VARCHAR2(4) RATE NUMBER(15,10)
insert into rates values ('EURO',1.1012); commit; update rates set rate = 1.1014; commit; update rates set rate = 1.1013; commit; delete rates; commit; insert into rates values ('EURO',1.1016); commit; update rates set rate = 1.1011; commit;
SQL> select * from rates; CURR RATE ---- ---------- EURO 1.1011
select versions_starttime, versions_endtime, versions_xid, versions_operation, rate from rates versions between timestamp minvalue and maxvalue order by VERSIONS_STARTTIME / VERSIONS_STARTTIME VERSIONS_ENDTIME VERSIONS_XID V RATE ---------------------- ---------------------- ---------------- - ---------- 01-DEC-03 03.57.12 PM 01-DEC-03 03.57.30 PM 0002002800000C61 I 1.1012 01-DEC-03 03.57.30 PM 01-DEC-03 03.57.39 PM 000A000A00000029 U 1.1014 01-DEC-03 03.57.39 PM 01-DEC-03 03.57.55 PM 000A000B00000029 U 1.1013 01-DEC-03 03.57.55 PM 000A000C00000029 D 1.1013 01-DEC-03 03.58.07 PM 01-DEC-03 03.58.17 PM 000A000D00000029 I 1.1016 01-DEC-03 03.58.17 PM 000A000E00000029 U 1.1011
SELECT UNDO_SQL FROM FLASHBACK_TRANSACTION_QUERY WHERE XID = '000A000D00000029'; UNDO_SQL ---------------------------------------------------------------------------- insert into "ANANDA"."RATES"("CURRENCY","RATE") values ('EURO','1.1013');
select rate, versions_starttime, versions_endtime from rates versions between timestamp to_date('12/1/2003 15:57:54','mm/dd/yyyy hh24:mi:ss') and to_date('12/1/2003 16:57:55','mm/dd/yyyy hh24:mi:ss') / RATE VERSIONS_STARTTIME VERSIONS_ENDTIME ---------- ---------------------- ---------------------- 1.1011
select rate, versions_starttime, versions_endtime from rates versions between scn 1000 and 1001 /
select versions_starttime, versions_endtime, versions_xid, versions_operation, rate from rates versions between timestamp to_date('12/11/2003 15:57:52', 'mm/dd/yyyy hh24:mi:ss') and maxvalue order by VERSIONS_STARTTIME / VERSIONS_STARTTIME VERSIONS_ENDTIME VERSIONS_XID V RATE ---------------------- ---------------------- ---------------- - ---------- 01-DEC-03 03.57.55 PM 000A000C00000029 D 1.1013 01-DEC-03 03.58.07 PM 01-DEC-03 03.58.17 PM 000A000D00000029 I 1.1016 01-DEC-03 03.58.17 PM 000A000E00000029 U 1.1011