oracle主键自增与序列的关系

来源:互联网 发布:引导页源码 编辑:程序博客网 时间:2024/05/18 02:51

create   sequence   name     
increment   by   x   //x为增长间隔     
start   with     x   //x为初始值     
maxvalue         x   //x为最大值       
minvalue         x   //x为最小值     
cycle                //循环使用,到达最大值或者最小值时,从新建立对象     
cache            x   //制定缓存序列值的个数     
                      
------------------------一个例子-----------------------
create   sequence   for_test  --序列名     
increment   by   1     --每次增加1
start   with   1     --从1开始
nomaxvalue     --没有最大值
nocache        --没有缓存序列

----------------------------创建测试表------------------
create table Test
(
id number(10) primary key,
name varchar2(20) not null,
desc  varchar2(200) null
)

-----------------------------使用序列-------------------
insert into Test
values(for_test.nextval,'序列测试','这是一个序列使用的例子')

--------------------序列使用结果查询-----------------
select * from test

原创粉丝点击