Oracle 中序列使用詳解

來源:互聯網
上載者:User

Oracle 中序列使用詳解:

create table test 
(pid integer primary key, 
  name varchar(20) 
  ); 
   
  select * from test; 
  insert into test values(1,'Jack'); 
 
create sequence test_seq;--建立序列  
select test_seq.nextval from dual;--每次使用後序列加一  
select test_seq.currval from dual;--查詢當前序列的值  
insert into test values(test_seq.nextval,'Jack Or Duck?');--序列的使用  
drop sequence test_seq;--刪除序列  
create sequence test_seq start with 8;--指定序列的初始值  
alter sequence test_seq minvalue 9;--設定序列的最小值  
alter sequence test_seq maxvalue 9999;--設定序列的最大值  
alter sequence test_seq increment by 1;--設定序列的步長  
drop sequence test_seq_1; 
create sequence test_seq_1 start with 3 minvalue 1 maxvalue 30 increment by 1; 
select test_seq_1.nextval from dual; 
alter sequence test_seq_1 cycle; 
alter sequence test_seq_1 nocycle;--關閉迴圈取值功能  
alter sequence test_seq_1 cache 10; 
 
--設定序列緩衝大小的作用,注:序列緩衝預設為20  
create sequence test_seq_2 start with 1 minvalue 1 maxvalue 20 increment by 3; 
alter sequence test_seq_2 cycle; 
 
--上述語句會報錯:Cache值必須小於cycle值  
 
alter sequence test_seq_2 increment by 2; 
alter sequence test_seq_2 cycle; 
--還是報錯  
alter sequence test_seq_2 increment by 1; 
alter sequence test_seq_2 cycle; 
--還是報錯  
alter sequence test_seq_2 maxvalue 21; 
alter sequence test_seq_2 cycle; 
--不報錯了  
 
--或者修改  
alter sequence test_seq_1 cache 5; 
--start with 1 and maxvalue 10 step 1 then 10 times cycle and bigger than 5  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.