Oracle10g New Feature -- 2.Flashback Records
在oracle10g中,使用者可以查詢紀錄在各時間點上的值,和每次對該紀錄的DML操作。
但是是不是在任何時候都可以查到從該紀錄產生起的所有更改歷史,還是有時間跨度的限制?Oracle為此功能多消耗多少空間?目前還是不太明白。
另外《Oracle Database 10g Top 20 Features for the DBA》() 中,對FLASHBACK_TRANSACTION_QUERY.UNDO_SQL的理解和引用例子中有錯,作筆記時作了改正。
[@more@]1. Flashback Versions QueryExample:SQL> desc rates
Name Null? Type
----------------- -------- ------------
CURRENCY VARCHAR2(4)
RATE NUMBER(15,10)
SQL> insert into rates values ('EURO',1.1012);
SQL> commit;
SQL> update rates set rate = 1.1014;
SQL> commit;
SQL> update rates set rate = 1.1013;
SQL> commit;
SQL> delete rates;
SQL> commit;
SQL> insert into rates values ('EURO',1.1016);
SQL> commit;
SQL> update rates set rate = 1.1011;
SQL> commit;
SQL> select * from rates;
CURR RATE
---- ----------
EURO 1.1011
The following query shows the changes made to the tableselect 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
VERSIONS_OPERATION column shows what operation (Insert/Update/Delete) was performed on the row,
VERSIONS_XID shows the identifier of the transaction that changed the row.
VERSIONS_STARTTIME, VERSIONS_ENDTIME, VERSIONS_XID, VERSIONS_OPERATION are pseudo-columns, similar to other familiar ones such as ROWNUM, LEVEL.
Other pseudo-columns—such as VERSIONS_STARTSCN and VERSIONS_ENDSCN—show the System Change Numbers at that time.
using the VERSIONS_XID value 000A000D00000029 from above, the UNDO_SQL value shows SQL to undo the DML indicated by OPERATION:
SELECT UNDO_SQL
FROM FLASHBACK_TRANSACTION_QUERY
WHERE XID = '000A000D00000029';
UNDO_SQL
Delete from “ANANDA”.”RATES” where ROWID = 'AAAMj2AAEAAAAFtAAA'
Finding Out Changes During a Period
- find out the value of the RATE column at 3:57:54 PM
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
- also use the SCN to find the value of a version in the past
select rate, versions_starttime, versions_endtime
from rates versions
between scn 1000 and 1001
/
- the changes from 3:57:52 PM only; not the complete range
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
SQL> desc rates
Name Null? Type
----------------- -------- ------------
CURRENCY VARCHAR2(4)
RATE NUMBER(15,10)
SQL> insert into rates values ('EURO',1.1012);
SQL> commit;
SQL> update rates set rate = 1.1014;
SQL> commit;
SQL> update rates set rate = 1.1013;
SQL> commit;
SQL> delete rates;
SQL> commit;
SQL> insert into rates values ('EURO',1.1016);
SQL> commit;
SQL> update rates set rate = 1.1011;
SQL> commit;
SQL> select * from rates;
CURR RATE
---- ----------
EURO 1.1011
The following query shows the changes made to the tableselect 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
VERSIONS_OPERATION column shows what operation (Insert/Update/Delete) was performed on the row,
VERSIONS_XID shows the identifier of the transaction that changed the row.
VERSIONS_STARTTIME, VERSIONS_ENDTIME, VERSIONS_XID, VERSIONS_OPERATION are pseudo-columns, similar to other familiar ones such as ROWNUM, LEVEL.
Other pseudo-columns—such as VERSIONS_STARTSCN and VERSIONS_ENDSCN—show the System Change Numbers at that time.
using the VERSIONS_XID value 000A000D00000029 from above, the UNDO_SQL value shows SQL to undo the DML indicated by OPERATION:
SELECT UNDO_SQL
FROM FLASHBACK_TRANSACTION_QUERY
WHERE XID = '000A000D00000029';
UNDO_SQL
Delete from “ANANDA”.”RATES” where ROWID = 'AAAMj2AAEAAAAFtAAA'
Finding Out Changes During a Period
- find out the value of the RATE column at 3:57:54 PM
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
- also use the SCN to find the value of a version in the past
select rate, versions_starttime, versions_endtime
from rates versions
between scn 1000 and 1001
/
- the changes from 3:57:52 PM only; not the complete range
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
OPERATION:
UNDO_SQL
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/207/viewspace-778618/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle10g New Feature -- 8. Tablespace ManagementOracle
- Oracle10g New Feature -- 4. Flashback DatabaseOracleDatabase
- Oracle10g New Feature -- 3.Flashback TableOracle
- Oracle10g New Feature -- 11. Wait InterfaceOracleAI
- Oracle10g New Feature -- 7. Rollback MonitoringOracle
- Oracle10g New Feature -- 6. Oracle Data PumpOracle
- Oracle10g New Feature -- 5.Temporary Tablespace GroupOracle
- oracle10g new feature -- 1. SqlplusOracleSQL
- Oracle10g New Feature:CRS(Cluster Ready Services) (zt)Oracle
- Oracle10g New Feature -- 9. ASM (Automatic Storage Management)OracleASM
- java new featureJava
- Oracle10g New Feature -- 14. OEM ( Oracle Enterprise Manager)Oracle
- Oracle10g New Feature -- 13. Automatic Shared Memory ManagementOracle
- Oracle10g New Feature --12. ASSM ( Automatic Segment Space Management )OracleSSM
- Oracle10g New Feature -- 10. AWR (Automatic Workload Repository)Oracle
- oracle10g new feature:對expdp並行方式的幾個測試Oracle並行
- 12c new feature
- 版本新特性(new feature)
- new feature ——>mysql to oracle MigrationMySqlOracle
- Oracle Database 12C New FeatureOracleDatabase
- 11g New Feature: Health monitor
- Oracle 12c Recover Table New FeatureOracle
- oracle 12c new feature 列不可見Oracle
- j2ee1.4 new feature請教banq
- Oracle10g New Features(1)Oracle
- 11g New Feature: Health monitor (Doc ID 466920.1)
- oracle 11g ocp new feature 1z0-050Oracle
- Test Negtive Role Set in a stream environmnet- 10g_new_feature
- oracle 12cR2 new feature dbca 命令可以建立standby 庫Oracle
- Does Goldengate Support The New Oracle 10g Flashback Feature? [ID 966212.1]GoOracle 10g
- C#9.0:RecordsC#
- Debug-Records
- New redo log sizing advisor in Oracle10gOracle
- 精讀《Records & Tuples for React》React
- zt_楊老師yangtingkun_11g new feature新特性系列文章
- oracle 12c R2 new feature 支援執行過的歷史命令Oracle
- oracle 12c new feature crsctl 停止資源時提供預覽確認功能Oracle
- [20130817]Oracle 12c new feature In-Database Archiving.txtOracleDatabase