Oracle Database 建立與查詢 Sequence

來源:互聯網
上載者:User

相關的 Oracle Database Sequence 資訊如下:

建立 Sequence 文法

create sequence <schema>.<table_name>_s
increment by 1
start with 1
maxvalue 99999999999999999999
minvalue 1
nocycle;
 
其中 :
incerment: 每次增加的數值
start    : Sequence 開始數值
maxvalue : Sequence 最大值
nocycle  : 當 Sequence 達最大值時,不重頭開始

取得下一筆 Sequence 值

select <Sequence_name>.nextval[@db_link]
  from dual;

查詢目前 Sequence 值

文法 1:
select <Sequence_name>.currval[@db_link]
  from dual;
 
Mark 提供: 若 "目前所在的 DB Session" 尚未執行 nextval, 就先執行 currval, 則會得到
ORA-08002: sequence DB_SESSION_ID.CURRVAL is not yet defined in this session 錯誤.
 
文法 2:
select last_number - 1
   from all_sequences
 where sequence_name = '<Sequence_name>';

修改 Sequence

如: Alter Sequence <Sequence_name> MaxValue 999999999999999;

注意事項

1) Sequence 不能直接用在 "等式 :=" 之後.如: vID := tomSeq.nextval;
2) Sequence 可以直接用在 "SQL" 之中.如: insert into tomTable values( tomSeq.nextval, ... );

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.