序列是Oracle中特有的对象, 用于生成一个自动递增的数列. 通常被用来作为主键的值.
a) 语法
create sequence seq_name [increment by n start with n maxvalue n|nomaxvalue // 10^27 or -1 minvalue n|nominvalue cycle|nocycle cache n|nocache] |
b) 创建学生序列
create sequence seq_student; |
查看序列的下一个值
select seq_student.nextval from dual; |
查看序列的当前值
select seq_student.currval from dual; |
insert into student values (seq_student.nextval, ‘小红‘, ‘女‘, 19, sysdate, ‘hong@sxt.com‘, 102); |
drop sequence seq_student; |
1 alter sequence student_id -- 序列名 也可以更改 2 minvalue 1 3 maxvalue 99999 4 start with 1 5 increment by 1 6 cycle -- 到99999后,从头开始 7 nocache;
注:
1、如果想要改变start的值,必须 drop sequence 再重建一个序列
2、如果想要改变minvalue的值,必须删除序列后再重新建立序列化。不可以修改序列化的minvalue。
原文:https://www.cnblogs.com/qiaoxin11/p/12784678.html