ORACLE 11G Flashback Versions Query
從oracle 10g開始,Flashback Technologies有了很大的改進,其中的Flashback Versions Query技術可以讓你輕鬆檢視到兩個時間點或scn點之間的同一資料的變動情況(必須是在flashback範圍以內)。例如下面的語句可以輕鬆檢視 t_dept表中09:00:00到09:16:00之間的資料變化情況:
SQL> SELECT * FROM mis.t_sys_dept
2 VERSIONS BETWEEN TIMESTAMP
3 to_timestamp('2011-10-26 09:00:00','yyyy-mm-dd hh24:mi:ss') AND
4 to_timestamp('2011-10-26 09:26:00','yyyy-mm-dd hh24:mi:ss')
5 WHERE DEPTid=5522;
------------------------------------------------------------------------------------------------------------------------------------
deptid deptcode deptname deptlevel terminated parent flag manager short depttype sort u8code
5522 101004 投資公司 2 0
1 1 5697
0 7 TZ
5522 101004 投資公司 2 0
1 0 5697
0 7 TZ
2 rows selected
表不能使用別名:如果在表名後面加上別名,則會報錯。
SQL> SELECT * FROM mis.t_sys_dept
d
2 VERSIONS BETWEEN TIMESTAMP
3 to_timestamp('2011-10-26 09:00:00','yyyy-mm-dd hh24:mi:ss') AND
4 to_timestamp('2011-10-26 09:16:00','yyyy-mm-dd hh24:mi:ss')
5 WHERE D.DEPTid=5522;
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
VERSIONS BETWEEN TIMESTAMP
*
ERROR AT line 2:
ORA-00933: SQL command NOT properly ended
偽列:
如果使用偽列,則不能使用*來統配表中所有的欄位:
SQL> SELECT versions_operation,* FROM oa.t_dept
2 VERSIONS BETWEEN TIMESTAMP
3 to_timestamp('2011-10-26 09:00:00','yyyy-mm-dd hh24:mi:ss') AND
4 to_timestamp('2011-10-26 09:26:00','yyyy-mm-dd hh24:mi:ss')
5 WHERE DEPTid=5522;
SELECT versions_operation,* FROM oa.t_dept
*
ERROR at line 1:
ORA-00936: missing expression
SQL> SELECT *,versions_operation FROM oa.t_dept
2 VERSIONS BETWEEN TIMESTAMP
3 to_timestamp('2011-10-26 09:00:00','yyyy-mm-dd hh24:mi:ss') AND
4 to_timestamp('2011-10-26 09:26:00','yyyy-mm-dd hh24:mi:ss')
5 WHERE DEPTid=5522;
SELECT *,versions_operation FROM oa.t_dept
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
使用偽列和欄位名:
SQL> SELECT deptid,deptname,versions_operation FROM oa.t_dept
2 VERSIONS BETWEEN TIMESTAMP
3 to_timestamp('2011-10-26 09:00:00','yyyy-mm-dd hh24:mi:ss') AND
4 to_timestamp('2011-10-26 09:26:00','yyyy-mm-dd hh24:mi:ss')
5 WHERE DEPTid=5522;
DEPTID DEPTNAME V
----------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
5522 投資公司 U
5522 投資公司 U
5522 投資公司
如果要使用*來統配表中所有的欄位,則必須在*前加上表名:
SQL> SELECT oa.t_dept.*,versions_operation FROM oa.t_dept
2 VERSIONS BETWEEN TIMESTAMP
3 to_timestamp('2011-10-26 09:00:00','yyyy-mm-dd hh24:mi:ss') AND
4 to_timestamp('2011-10-26 09:26:00','yyyy-mm-dd hh24:mi:ss')
5 WHERE DEPTid=5522;
------------------------------------------------------------------------------------------------------------------------------------
deptid deptcode deptname deptlevel terminated parent flag manager short depttype sort u8code
5522 101004 投資公司 2 0
1 1 5697
0 7 TZ
5522 101004 投資公司 2 0
1 0 5697
0 7 TZ
2 rows selected
不知道為什麼在Flashback Versions Query中不能用表的別名,難道是oracle的BUG?
注:關於Flashback Pseudocolumns介紹
VERSIONS_STARTSCN
Starting SCN when the row was first created. This identifies the
SCN when the data first took on the values displayed in the row
version.If NULL, the row version was created before the lower time bound
of the query BETWEEN clause.
VERSIONS_STARTTIME
Starting TIMESTAMP when the row version was first created. This
identifies the time when the data first took on the values displayed in
the row version. If NULL, the row version was created before the lower
time bound of the query BETWEEN clause.
VERSIONS_ENDSCN
Ending SCN when the row version expired. This identifies the row
expiration SCN. If NULL, then either the row version is still current
or
the row corresponds to a DELETE operation.
VERSIONS_ENDTIME
Ending TIMESTAMP when the row version expired. This identifies
the row expiration time. If NULL, then either the row version is still
current
or the row corresponds to a DELETE operation.
VERSIONS_XID
Identifier of the transaction that created the row version.
VERSIONS_OPERATION
This is the operation performed by the transaction that modified the data. The values are I for insertion, D for deletion, or U for update.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-1148699/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle OCP 1Z0 053 Q704(Flashback Versions Query)Oracle
- ORACLE Flashback Query偽列Oracle
- oracle 10g flashback version query 和 flashback transaction query實驗Oracle 10g
- Overview of Oracle Flashback Query I (366)ViewOracle
- Overview of Oracle Flashback Query II (367)ViewOracle
- oracle10g之flashback version query 和flashback transaction query 實驗Oracle
- Oracle10g的Flashback之Flashback Transaction QueryOracle
- flashback version query in oracle 10gOracle 10g
- 【Flashback】Flashback Query功能實踐
- flashback技術之---flashback query
- Oracle閃回技術--Flashback Version QueryOracle
- Oracle Flashback query查詢的侷限Oracle
- Oracle10g的Flashback version QueryOracle
- flashback version query和 flashback transaction query簡單應用
- flashback技術之---flashback Transaction Query
- flashback技術之---flashback version query
- Flashback Query Benefits (368)
- flashback總結四之Flashback_Query
- ORACLE 11G FLASHBACK FEATUREOracle
- query result cache in oracle 11gOracle
- flashback總結六之Flashback_Transaction_Query
- 【實驗】【Flashback】Flashback Transaction Query功能實踐
- oracle flashback特性(1.4)--閃回查詢之Transaction queryOracle
- 閃回之 Flashback Query (dml表、過程、函式、包等)、Flashback version Query函式
- flashback總結五之Flashback_Query_Version(上)
- flashback query閃回資料
- flashback drop/query/table/database/archiveDatabaseHive
- Flashback Query閃回查詢
- Flashback Query的應用(轉帖)
- oracle檢視flashback_transaction_query中列operation為unknownOracle
- Oracle OCP 1Z0-053 Q252(Flashback Version Query)Oracle
- flashback總結五之Flashback_Query_Version(下)_補充
- Oracle 11g開啟閃回功能FlashbackOracle
- Oracle Database 11g閃回技術flashbackOracleDatabase
- oracle performance Features and VersionsOracleORM
- FLASHBACK_TRANSACTION_QUERY 11G R2. UNDO_SQL為NULL的問題SQLNull
- Oracle OCP 1Z0 053 Q387(FLASHBACK_TRANSACTION_QUERY)Oracle
- Oracle OCP 1Z0 053 Q63(flashback_transaction_query)Oracle