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 Flashback Query偽列Oracle
- Oracle閃回技術--Flashback Version QueryOracle
- Flashback Query(轉)
- flashback query閃回資料
- 【FLASHBACK】Oracle flashback data archive 介紹OracleHive
- [20180724]Flashback query和子游標共享.txt
- oracle 10g flashback databaseOracle 10gDatabase
- Oracle 備份恢復之 FlashbackOracle
- [20190214]11g Query Result Cache RC Latches.txt
- [20190214]11g Query Result Cache RC Latches補充.txt
- Oracle之11g DataGuardOracle
- Oracle 11G 安裝文件Oracle
- benchmark 壓測Oracle 11gOracle
- sysbench壓測Oracle 11gOracle
- 在Oracle DG Standby庫上啟用flashback database功能OracleDatabase
- ORACLE 閃回檢視v$flashback_database_log/statOracleDatabase
- Older Versions Of EclipseEclipse
- [20230308]versions偽列versions_starttime疑問2.txt
- Oracle 11G 安裝 bbed 工具Oracle
- oracle 11g data guard維護Oracle
- oracle 11g OEM在哪裡找到???Oracle
- oracle 11g 常用命令Oracle
- Oracle 11g RAC Silent Install For NFSOracleNFS
- Oracle 11g刪除庫重建Oracle
- Oracle 11G 修改scan_ipOracle
- Oracle 11G RAC叢集安裝(3)——安裝OracleOracle
- Oracle Linux 6.7 靜預設安裝Oracle 11gOracleLinux
- manage-docs-versions
- 2.3.3.3.2 Applications at Different VersionsAPP
- Oracle 12.2新特性: PDB級閃回資料庫(Flashback PDB)Oracle資料庫
- 【FLASHBACK】Oracle閃回及回收站相關語句參考Oracle
- Oracle 11g RAC 監聽日常管理Oracle
- Oracle 11g 052題庫解析1Oracle
- oracle 11g datagurd主從切換Oracle
- ORACLE10G升級11GOracle
- Oracle 11g RAC手動新增serviceOracle
- Oracle 11g dg broker自動failoverOracleAI
- Automatic Diagnostic Repository (ADR) with Oracle Net for 11gOracle
- Oracle 11g關閉開啟AWROracle