OCA SQL試題
Evaluate the following statements:
CREATE TABLE digits (id NUMBER(2), description VARCHAR2(15)); INSERT INTO digits VALUES (1,'ONE'); UPDATE digits SET description ='TWO' WHERE id=1; INSERT INTO digits VALUES (2,'TWO'); COMMIT; DELETE FROM digits; SELECT description FROM digits VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE;
What would be the outcome of the above query?
A. It would not display any values.
B. It would display the value TWO once.
C. It would display
the value TWO twice.
D. It would display the values ONE, TWO, and TWO.
在 Oracle9iDatabase 中,我們看到它推出了以閃回查詢形式表示的“時間機器”。該特性允許 DBA 看到特定時間的列值,只要在還原段中提供該資料區塊此前鏡像的拷貝即可。但是,閃回查詢只提供某時刻資料的固定快照,而不是在兩個時間點之間被更改資料的運行狀態表示。某些應用程式,如涉及到外幣管理的應用程式,可能需要瞭解一段時期內數值資料的變化,而不僅僅是兩個時間點的數值。由於閃回版本查詢特性,Oracle Database 10g能夠更方便高效地執行該任務。
使用方法:
VERSIONS BETWEEN TIMESTAMP [lower bound] AND [upper bound]
VERSIONS BETWEEN SCN [lower bound] AND [upper bound]
lower bound/ upper bound 可以是具體的timestamp/scn, 也可以是關鍵字minvalue/maxvalue. 這些關鍵字讓Oracle去找到所有的versions, 當然這要受制於undo_retention參數設定的大小,畢竟這部分資訊是放在undo segment上的。
Oracle 10g提供了一些pseudo-columns來協助我們分析每個version的資料,
VERSIONS_STARTTIME (start timestamp of version);VERSIONS_STARTSCN (start SCN of version);VERSIONS_ENDTIME (end timestamp of version);VERSIONS_ENDSCN (end SCN of version);VERSIONS_XID (transaction ID of version); VERSIONS_OPERATION (DML operation of version);select description,versionS_starttime, versionS_endtime, versionS_xid,versionS_operationfrom digitsversions between timestamp minvalue and maxvalue ;