您的位置:首页 > 数据库 > Oracle

oracle中创建自增长序列

2012-07-06 17:03 302 查看
首先创建序列:

create sequence
[b]incr_stu_id
_seq

minvalue 1

start with 1

increment by 1

[/b]

nomaxvalue

nocache;



然后创建触发器:



create or replace trigger incr_stu_id_trig

before insert on students

for each row

begin

select incr_stu_id_sequ.nextval into:new.id from dual;

end incr_stu_id_trig;


最后可以使用了:

insert into students(name,major,score) values('zhangsan','history',89);

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: