版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yhzhaohy/article/details/83016344
Sequence是数据库系统按照一定的规则自动增加的数字序列,主要用于生成数据库数据记录。这个序列一般作为代理主键(因为不会重复)。
新建Sequence:
-- create sequence
create sequence SEQ_sailingTest
minvalue 1
maxvalue 9999999
start with 1
increment by 1 --递增间隔
cache 20; --nocache
表中插入数据使用Sequence:
--SEQ.nextval,SEQ.currval
insert into sailing_test(id,name) values (SEQ_sailingTest.nextval,sailing);
--currVal:返回 sequence的当前值
--nextVal: 增加sequence的值,然后返回 增加后sequence值
修改/删除sequence:
--alert sequence:
alert sequence SEQ_sailingTest
minvalue 1
maxvalue 100000
start with 99
increment by 2 --递增间隔
nocache;
--drop sequence:
drop sequence SEQ_sailingTest;
查询sequence:
--查询当前用户的序列
select * from user_sequences
--查询所有的序列
select * from all_sequences
--模糊查询某序列
elect * from user_sequences where sequence_name like '%sailingTest%'