首页 > 数据库技术 > 详细

oracle 序列

时间:2017-04-08 12:57:58      阅读:224      评论:0      收藏:0      [点我收藏+]

--序列
-- 使用序列是实现自增 在mysql中由idtify自增 oracle里没有这个自增函数 只能创建序列
drop table student;
create table student(
sid int primary key,
sname varchar2(10)
)

select *from student;

--为student创建序列
drop sequence stu_seq_1;
create sequence stu_seq_1
start with 1000
increment by 1
NOMAXVALUE
NOMINVALUE;

select stu_seq_1.nextval from dual; --nextval 查询下一个序列并且将创建出来
select stu_seq_1.currval from dual; --currval 查询当前序列
insert into student values(stu_seq_1.nextval,‘a‘);
insert into student values(stu_seq_1.nextval,‘b‘);
select *from student;

--修改序列
--语法 alert sequence 序列名 要修改的值
alter sequence stu_seq_1 increment by 10;
insert into student values(stu_seq_1.nextval,‘c‘);
insert into student values(stu_seq_1.nextval,‘d‘);
--删除序列

drop sequence stu_seq_1;

insert into student values(stu_seq_1.nextval,‘T‘);--报错

oracle 序列

原文:http://www.cnblogs.com/KOAN-lcd/p/6681159.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!