Oracle10g的current_scn是如何计算的?

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

前几天有一个朋友问我一个问题:
Oracle10g的current_scn是如何计算的?

我们知道Oracle10g在v$database视图中引入了current_scn,这个SCN来自底层表,代表当前的SCN,在Oracle9i中我们可以通过dbms_flashback.get_system_change_number来获得系统的SCN。

但是注意current_scn还是有所不同的,我们看一下一个查询:

[oracle@danaly ~]$ sqlplus '/ as sysdba'

 

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 21 10:15:08 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

SQL> @scn
SQL> col current_scn for 99999999999999999
SQL> select current_scn from v$database;

CURRENT_SCN
------------------
8910961765228

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

CURRENT_SCN
------------------
8910961765228

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

CURRENT_SCN
------------------
8910961765228

SQL> select current_scn from v$database;

CURRENT_SCN
------------------
8910961765229

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

CURRENT_SCN
------------------
8910961765229

SQL> select dbms_flashback.get_system_change_number current_scn from dual;

CURRENT_SCN
------------------
8910961765229

SQL> select current_scn from v$database;

CURRENT_SCN
------------------
8910961765230

 

我们看到current_scn的查询会直接导致SCN的增进,而其他方式并不会。也就是说在这里的current_scn就像是一个Sequence一样,查询会导致增进。这也很好理解,v$database只能通过增进当前的SCN才能保证获得的SCN是Current的。可是如果不查询呢?这个值肯定是不会增长的。

也就是说你不查询就不知道current_scn的值,你查询它就变化,是不是有点向薛定谔的猫的那种感觉?

posted on 2008-11-12 18:00  一江水  阅读(695)  评论(0编辑  收藏  举报