oracle 11.2.0.4 sequence之dba_sequences last_number含義測試之一
測試結論
1,檢視dba_sequences之last_number含義
Last sequence number written to disk. If a sequence uses caching, the number written to disk is the last number placed in the sequence cache.
This number is likely to be greater than the last sequence number that was used.
a,last_number為寫入到磁碟的最後的序列值
b,如果序列使用cache,last_number為儲存在CACHE中最大或最後的序列值
c,last_number的值很可能會大於已使用序列的最後的值
2,可見只要序列的當前值sequence_name.currval不超過last_number,則LAST_NUMBER不會發生變化
測試明細
1,資料庫版本
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2,dba_sequences官方定義
SQL> desc dba_sequences;
Name Null? Type
----------------------------------------- -------- ----------------------------
SEQUENCE_OWNER NOT NULL VARCHAR2(30)
SEQUENCE_NAME NOT NULL VARCHAR2(30)
MIN_VALUE NUMBER
MAX_VALUE NUMBER
INCREMENT_BY NOT NULL NUMBER
CYCLE_FLAG VARCHAR2(1)
ORDER_FLAG VARCHAR2(1)
CACHE_SIZE NOT NULL NUMBER
LAST_NUMBER NOT NULL NUMBER
3,建立序列
SQL> create sequence seq_zxy;
Sequence created.
4,檢視剛建立的序列資訊,可見last_number為1
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 1
5,currval不能直接使用,必須先要nextval之後再使用currval
SQL> select seq_zxy.currval from dual;
select seq_zxy.currval from dual
*
ERROR at line 1:
ORA-08002: sequence SEQ_ZXY.CURRVAL is not yet defined in this session
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 1
SQL>
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
1
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 21
SQL>
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
2
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 21
6,變化sequence cache_size,可知cache size變化後last_number也會變化
SQL> alter sequence seq_zxy cache 200;
Sequence altered.
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 200 3
7,檢視dba_sequences之last_number含義
Last sequence number written to disk. If a sequence uses caching, the number written to disk is the last number placed in the sequence cache.
This number is likely to be greater than the last sequence number that was used.
a,last_number為寫入到磁碟的最後的序列值
b,如果序列使用cache,last_number為儲存在CACHE中最大或最後的序列值
c,last_number的值很可能會大於已使用序列的最後的值
8,可見只要序列的當前值不超過last_number,則LAST_NUMBER不會發生變化
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
4
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 200 203
SQL>
SQL>
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
5
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 200 203
SQL>
1,檢視dba_sequences之last_number含義
Last sequence number written to disk. If a sequence uses caching, the number written to disk is the last number placed in the sequence cache.
This number is likely to be greater than the last sequence number that was used.
a,last_number為寫入到磁碟的最後的序列值
b,如果序列使用cache,last_number為儲存在CACHE中最大或最後的序列值
c,last_number的值很可能會大於已使用序列的最後的值
2,可見只要序列的當前值sequence_name.currval不超過last_number,則LAST_NUMBER不會發生變化
測試明細
1,資料庫版本
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2,dba_sequences官方定義
SQL> desc dba_sequences;
Name Null? Type
----------------------------------------- -------- ----------------------------
SEQUENCE_OWNER NOT NULL VARCHAR2(30)
SEQUENCE_NAME NOT NULL VARCHAR2(30)
MIN_VALUE NUMBER
MAX_VALUE NUMBER
INCREMENT_BY NOT NULL NUMBER
CYCLE_FLAG VARCHAR2(1)
ORDER_FLAG VARCHAR2(1)
CACHE_SIZE NOT NULL NUMBER
LAST_NUMBER NOT NULL NUMBER
3,建立序列
SQL> create sequence seq_zxy;
Sequence created.
4,檢視剛建立的序列資訊,可見last_number為1
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 1
5,currval不能直接使用,必須先要nextval之後再使用currval
SQL> select seq_zxy.currval from dual;
select seq_zxy.currval from dual
*
ERROR at line 1:
ORA-08002: sequence SEQ_ZXY.CURRVAL is not yet defined in this session
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 1
SQL>
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
1
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 21
SQL>
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
2
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 20 21
6,變化sequence cache_size,可知cache size變化後last_number也會變化
SQL> alter sequence seq_zxy cache 200;
Sequence altered.
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 200 3
7,檢視dba_sequences之last_number含義
Last sequence number written to disk. If a sequence uses caching, the number written to disk is the last number placed in the sequence cache.
This number is likely to be greater than the last sequence number that was used.
a,last_number為寫入到磁碟的最後的序列值
b,如果序列使用cache,last_number為儲存在CACHE中最大或最後的序列值
c,last_number的值很可能會大於已使用序列的最後的值
8,可見只要序列的當前值不超過last_number,則LAST_NUMBER不會發生變化
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
4
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 200 203
SQL>
SQL>
SQL> select seq_zxy.nextval from dual;
NEXTVAL
----------
5
SQL> select sequence_owner,sequence_name,min_value,max_value,increment_by,cycle_flag,order_flag,cache_size,last_number from dba_sequences where sequence_owner='SYS'
2 and sequence_name='SEQ_ZXY';
SEQUENCE_OWNER SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS SEQ_ZXY 1 1.0000E+28 1 N N 200 203
SQL>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2141184/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle 11.2.0.4之oracle database db link之測試明細之一OracleDatabase
- 測試oracle 11.2.0.4的remote_login_password引數含義OracleREM
- Oracle中sequence cache的測試Oracle
- 基於redhat 6.5 oracle 11.2.0.4測試tts傳輸表空間之資料庫遷移之一RedhatOracleTTS資料庫
- oracle sequence 試用Oracle
- oracle 10.2.0.1 rac的lmd程式的含義之一Oracle
- Oracle之Sequence(序列)Oracle
- oracle 11.2.0.4使用dbms_stats收集統計資訊statistics及刪除和還原相關測試之一Oracle
- oracle 11.2.0.4 使用easy connect naming定義db link淺析之一Oracle
- oracle 11.2.0.4 db link建立之sid語法一點淺談之一Oracle
- redhat 6.5之oracle 11.2.0.4 asm例項異常抽取asm配置資訊之amdu初識之一RedhatOracleASM
- oracle之 11.2.0.4 bbed安裝Oracle
- oracle常用包之dbms_rowid oracle rowid含義分析Oracle
- oracle rowid 的含義Oracle
- oracle xtts資料庫遷移方法測試之一OracleTTS資料庫
- oracle10g_expdp工具測試學習_之一Oracle
- oracle10g_impdp工具測試學習_之一Oracle
- Oracle主要版本命名含義Oracle
- oracle中斜槓(/)的含義Oracle
- oracle壓力測試之orastress!OracleAST
- ORACLE SEQUENCEOracle
- Oracle資料恢復顧問(DRA)使用測試 (之一)Oracle資料恢復
- 基於redhat 6.5 oracle 11.2.0.4初識oracle asm diskgroup相關概念之一RedhatOracleASM
- Oracle Statspack各項指標含義Oracle指標
- oracle壓力測試之orabm(二)Oracle
- oracle壓力測試之orabm(三)Oracle
- oracle壓力測試之orabm(一)Oracle
- ORACLE SEQUENCE用法Oracle
- Oracle - Sequence序列Oracle
- Oracle Sequence NocacheOracle
- Oracle序列sequenceOracle
- Oracle 基本操作之 建立自增欄位方法-ORACLE SEQUENCEOracle
- ORACLE的使用試驗-- RMAN之一Oracle
- oracle buffer busy waits等待的含義OracleAI
- 部分Oracle 配置檔案引數含義Oracle
- oracle 11.2.0.1以及oracle 11.2.0.4資料庫的時區time zone相關概念之一Oracle資料庫
- Oracle Sequence Audses$研究Oracle
- oracle sequence語法Oracle