ORACLE学习06-序列
时间:2021-07-01 10:21:17
帮助过:3人阅读
drop table student
cascade constraints;
create table student(
sid int not null primary key,
sno number(
12),
sname varchar2(
32),
address varchar2(
64),
birthday date
);
格式:
create sequence stu_seq
--序列名
increment
by 1 -- 每次加几个
start
with 1 -- 从1开始计数,初始值
nomaxvalue
/maxvalue n
/minvalue n
-- 不设置最大值/最大/最小
nocycle
/cycle
-- 一直累加,不循环/循环
cache
10/nocache;
--缓存几个值,默认20
例子:
create sequence stu_seq
increment by 1
start with 1
minvalue 1
maxvalue 999999999
nocycle
cache 10
三、查询序列
nextval: 返回序列中下一个有效的值,任何用户都可以引用
currval: 中存放序列的当前值
例子:
select
stu_seq.nextval "nextval",
stu_seq.currval "currval"
from dual;
insert into student
(sid,sno,sname,address)
values
(stu_seq.nextval,1001,
‘张三‘,
‘北京海淀‘)
四、修改序列
alter sequence 序列名
[increment by n]
[{maxvalue/ minvalue n|nomaxvalue}]
[{cycle|nocycle}]
[{cache n|nocache}];
不能修改序列的初始值
五、删除序列
drop sequence 序列名;
ORACLE学习06-序列
标签: