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 bbed安裝Oracle
- ORACLE SEQUENCE用法Oracle
- oracle buffer busy waits等待的含義OracleAI
- oracle壓力測試之orastress!OracleAST
- oracle壓力測試之orabm(二)Oracle
- oracle壓力測試之orabm(三)Oracle
- oracle壓力測試之orabm(一)Oracle
- ORACLE 11.2.0.4 RAC RMAN異機恢復之ORA-15001Oracle
- oracle的scn及sequenceOracle
- Oracle 10.2.0.5升級至11.2.0.4Oracle
- ORACLE 11.2.0.4 DG(Broker) for linux 部署OracleLinux
- 快速顯示oracle錯誤號的含義Oracle
- oracle 11.2.0.4 rac節點異常當機之ORA-07445Oracle
- [20220321]探究oracle sequence.txtOracle
- Oracle:Oracle RAC 11.2.0.4 升級為 19cOracle
- oracle rac 11.2.0.3 升級到11.2.0.4Oracle
- [20211025]12c sequence nocache測試補充.txt
- Linux之相關英文縮寫含義Linux
- idea之【Before launch】選項的含義Idea
- Oracle replayc測試Oracle
- 不同於Oracle:SEQUENCE的區別Oracle
- [20220322]探究oracle sequence 2.txtOracle
- Solaris下Oracle RAC 11.2.0.4 安裝方法Oracle
- Oracle 11.2.0.4 Dataguard兩則故障處理Oracle
- 【UP_ORACLE】使用AutoUpgrade工具升級Oracle 11.2.0.4至12.2.0.1Oracle
- 從Oracle 11.2.0.4 BUG到Oracle子查詢展開分析Oracle
- 【XTTS】Oracle XTTS V4--Oracle11.2.0.4+ 遷移升級TTSOracle
- bootstrap含義boot
- instanceof 含義
- DBA面試資源合集(含Oracle、MySQL、Redis等)面試OracleMySqlRedis
- oracle資料庫11.2.0.3升級到11.2.0.4Oracle資料庫
- Oracle 11.2.0.4 physical dataguard和snapshot dataguard切換Oracle
- ORACLE壓力測試Oracle
- Oracle TDE加密測試Oracle加密
- 查閱linux tcp核心引數kernel parameter tcp_max_syn_backlog含義之一LinuxTCP
- oracle 11.2.0.4 rac叢集等待事件enq: TM - contentionOracle事件ENQ
- redhat7.2靜默安裝Oracle11.2.0.4RedhatOracle
- Oracle中Nextval用法SEQUENCE與SYS_GUID()OracleGUI
- Oracle Linux 6.7中 Oracle 11.2.0.4 RAC叢集CRS異常處理OracleLinux