Oracle HowTo:How to get Oracle SCN?

sqysl發表於2009-01-28

之前簡單的介紹過一下 ,主要可以透過兩種方式:
1.在Oracle9i及以上版本中
可以使用dbms_flashback.get_system_change_number來獲得
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
                 2982184
2.在Oracle9i之前
可以透過查詢x$ktuxe獲得最接近當前系統scn值
X$KTUXE-------------[K]ernel [T]ransaction [u]ndo Transa[x]tion [E]ntry (table)
SQL> select max(ktuxescnw*power(2,32)+ktuxescnb) from x$ktuxe;
MAX(KTUXESCNW*POWER(2,32)+KTUXESCNB)
------------------------------------
                             2980613
3.透過oradebug獲取
以前在 的站點上看到使用oradebug 的方法,轉引在這裡:
[oracle@neirong oracle]$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.4.0 - Production on Wed Dec 21 21:04:24 2005
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
SQL> col a for 999999999999
SQL> oradebug setmypid
Statement processed.
SQL> oradebug DUMPvar SGA kcsgscn_
kcslf kcsgscn_ [1200BC68, 1200BC88) = 0000 0003 BA84F392 00071266 00000000 00000000 00000000 00000000 1200B948
SQL> select to_number('3BA84F392','xxxxxxxxxxxx') a from dual;
            A
-------------
  16014177170
SQL> select dbms_flashback.get_system_change_number a from dual;
            A
-------------
  16014177255
SQL>
方法有多種,但是涉及的知識各有巧妙不同,深入研究一下都是很有意思的.

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

相關文章