Oracle10g與oracle11g中current_scn計算差別

楊奇龍發表於2010-05-02

我們知道Oracle10g在v$database檢視中引入了current_scn,這個SCN來自底層表,代表當前的SCN,在Oracle9i中我們可以透過dbms_flashback.get_system_change_number來獲得系統的SCN。我的版本是oracle11g的。

但是注意current_scn還是有所不同的,看一下一個查詢:
SQL> col current_scn for 99999999999999999
SQL> select current_scn from v$database;
       CURRENT_SCN                                                             
------------------                                                             
           1941617                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941650                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941675                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941678                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941683                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941689                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941691                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941762                                                             

SQL> conn system/yang as sysdba
已連線。
SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941780                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941794                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941794                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941795                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941797                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941797                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941798                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941799                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941799                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941799                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941800                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941800                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941801                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941801                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941801                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941802                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941802                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941802                                                             

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

       CURRENT_SCN                                                             
------------------                                                             
           1941803                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941806                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941808                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941809                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941811                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941812                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941814                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941815                                                             

SQL> select current_scn from v$database;

       CURRENT_SCN                                                             
------------------                                                             
           1941817       
                                                      

我們看到current_scn的查詢會直接導致SCN的增進,而其他方式並不會,至少執行兩次時不會。也就是說在這裡的current_scn就像是一個Sequence一樣,查詢會導致增進。這也很好理解,v$database只能透過增進當前的SCN才能保證獲得的SCN是Current的。可是如果不查詢呢?這個值肯定是不會增長的。

這裡 和蓋國強大師 說點不一樣。

http://www.eygle.com/archives/2007/06/oracle10g_current_scn.html

有點疑惑?那位朋友能給個解答!先謝謝了。。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-661762/,如需轉載,請註明出處,否則將追究法律責任。

相關文章