-- 序列 在很多数据库中都存在一个自动增长的列,如果现在想要在Oracl中完成自动增长的功能,
-- 则只能依靠序列完成,所有自动增长操作需要手工处理.并且Oracle将序列值装入内存可以提高访问效率
-- 语法:
/*
create sequence 序列名称
increment by n
下个增长为n
start with n
起始序列为 n
maxvalue n | nomaxvalue
最大序列值
minvalue n | nominvalue
最小值
cycle | nocycle
是否循环 1,2,3,1,2,3
cache n \ nocache
缓存的数量
*/
create sequence stu_stuid_seq
increment by 10
start with 120
maxvalue 9999
nocache
nocycle;
-- 如何从序列获取值
-- currval :当前值
-- nextval:下一个值
-- 注意:currval需要在调用nextval之后才能使用
-- 永不回头,往下取数据,无论发生异常,回滚
-- 下一个序列
select stu_stuid_seq.nextval from dual;
-- 当前序列
select stu_stuid_seq.currval from dual;
Oracle序列基本语法
最新推荐文章于 2020-07-23 18:08:13 发布