Oracle10g中的current_scn是怎樣計算的

來源:互聯網
上載者:User

問: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的值,只要查詢它就會出現變化。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.