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
Oracle 中序列使用詳解
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.