CREATE SEQUENCE sequence //创建序列名称 [INCREMENT BY n] //递增的序列值是n 如果n是正数就递增,如果 是负数就递减 默认是1 [START WITH n] //开始的值,递增默认是minvalue 递减是 // maxvalue [{MAXVALUE n | NOMAXVALUE}] //最大值 [{MINVALUE n | NOMINVALUE}] //最小值 [{CYCLE | NOCYCLE}] //循环/不循环 [{CACHE n | NOCACHE}];//分配并存入到内存中
NEXTVAL 返回序列中下一个有效的值,任何用户都可以引用
CURRVAL 中存放序列的当前值 NEXTVAL 应在 CURRVAL 之前指定 ,二者应同时有效select emp_id_seq.nextval from dual;
select emp_id_seq.currval from dual;
使用DROP SEQUENCE 语句删除序列
修改序列
Alter sequence seqEmp maxvalue 5;
Select seqEmp.nextval from dual;
create table cdpt(
id number(6),name varchar2(30),constraint pk_id primary key(id));Create sequence seq_cdpt
Increment by 1Start with 1Maxvalue 999999Minvalue 1Nocyclenocacheinsert into cdpt values(seq_cdpt.nextval,’feffefe’);
commit;select * from cdpt;