1.创建sequence
CREATE SEQUENCE SEQ_NAME
INCREMENT BY n
START WITH n
Maxvalue 99999
Cycle
Cache n;
SEQ_NAME:计数器的名字
INCREMENT BY:每次增加幅度
START WITH: 起始序号
Maxvalue:最大值;可不设置最大值---NOMAXvalue
Cycle:循环使用;可不循环---NOCYCLE
Cache: 缓存序列个数
例:
CREATE SEQUENCE test_seq
INCREMENT BY 1
START WITH 100
Maxvalue 99999
Cycle
Cache 10;
2.查看sequence(新的计数器sequence必须先使用nextval后才可以使用currval)
查询sequence的当前值:select test_seq.currval from dual;
查询sequence下一个值:select test_seq.nextval from dual;
3.删除sequence :
drop sequence seq_name;