您好,登錄后才能下訂單哦!
該內(nèi)容來源官網(wǎng):
http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions161.htm#BABEHBCB
其用法很簡單
scn_to_timestamp(number),其中number指的是系統(tǒng)當(dāng)前生產(chǎn)的SCN
文檔中NOTE部分提到一個(gè)內(nèi)容值得注意:
The association between an SCN and a timestamp when the SCN is generated is remembered by the database for a limited period of time. This period is the maximum of the auto-tuned undo retention period, if the database runs in the Automatic Undo Management mode, and the retention times of all flashback archives in the database, but no less than 120 hours. The time for the association to become obsolete elapses only when the database is open. An error is returned if the SCN specified for the argument to SCN_TO_TIMESTAMP
is too old.
這里說到當(dāng)SCN生成時(shí)數(shù)據(jù)庫在有限的期限內(nèi)保留SCN和TIMESTAMP間的關(guān)系,這個(gè)期限是由undo最大的保存時(shí)間來確定,如果數(shù)據(jù)庫運(yùn)行了UNDO的自動(dòng)管理,并且存儲(chǔ)的閃回歸檔不小于120小時(shí),則僅當(dāng)數(shù)據(jù)庫開啟時(shí)這個(gè)關(guān)系會(huì)過期,當(dāng)通過SCN_TO_TIMESTAMP函數(shù)查詢時(shí),會(huì)返回參數(shù)太舊的錯(cuò)誤提示。
同時(shí)文檔中提到一個(gè)有趣的用法,Oracle提供了一個(gè)叫ORA_ROWSCN的虛擬列,當(dāng)你對(duì)某些表進(jìn)行查詢是,通過SCN_TO_NUMBER()參數(shù)中指定該虛擬字段,其返回的結(jié)果是該表中行最后一次升級(jí)的時(shí)間。
SQL> select scn_to_timestamp(ORA_ROWSCN) from tbilllog3; SCN_TO_TIMESTAMP(ORA_ROWSCN) --------------------------------------------------------------------- 05-JAN-15 02.25.28.000000000 PM 05-JAN-15 05.28.56.000000000 PM
其目的主要在于閃回查詢,通過時(shí)間戳將數(shù)據(jù)回退到某一個(gè)時(shí)間點(diǎn)。例子可以看一下官網(wǎng)中的介紹
如果指定的是未來的某個(gè)SCN數(shù),則會(huì)出現(xiàn)如下錯(cuò)誤,
SQL> select scn_to_timestamp(2095591) from dual; select scn_to_timestamp(2095591) from dual * ERROR at line 1: ORA-08181: specified number is not a valid system change number ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。