eygle.com   eygle.com
eygle.com eygle
eygle.com  
 

« 人生若只如初见 | Blog首页 | Oracle bloggers on frappr »

Oracle HowTo:How to get Oracle SCN?

之前简单的介绍过一下如何获得当前数据库的SCN值,主要可以通过两种方式:

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获取

以前在l2g32003的站点上看到使用oradebug获取SCN的方法,转引在这里:

[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) = 00000003 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



方法有多种,但是涉及的知识各有巧妙不同,深入研究一下都是很有意思的.


历史上的今天...
    >> 2011-01-06文章:
    >> 2010-01-06文章:
    >> 2008-01-06文章:

无觅

By eygle on 2006-01-06 20:51 | Comments (3) | HowTo | Internal | 621 |

3 Comments

为何我使用前两种方法,在同一时间获取的SCN不一致?

x$ktuxe
为啥我的10G里没有这个表?

我的有:

SQL> desc x$ktuxe
Name Null? Type
----------------------------------------- -------- ----------------------------
ADDR RAW(8)
INDX NUMBER
INST_ID NUMBER
KTUXEUSN NUMBER
KTUXESLT NUMBER
KTUXESQN NUMBER
KTUXERDBF NUMBER
KTUXERDBB NUMBER
KTUXESCNB NUMBER
KTUXESCNW NUMBER
KTUXESTA VARCHAR2(16)
KTUXECFL VARCHAR2(24)
KTUXEUEL NUMBER
KTUXEDDBF NUMBER
KTUXEDDBB NUMBER
KTUXEPUSN NUMBER
KTUXEPSLT NUMBER
KTUXEPSQN NUMBER
KTUXESIZ NUMBER

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production


CopyRight © 2004~2020 云和恩墨,成就未来!, All rights reserved.
数据恢复·紧急救援·性能优化 云和恩墨 24x7 热线电话:400-600-8755 业务咨询:010-59007017-7040 or 7037 业务合作: marketing@enmotech.com