oracle中创建自增长序列

首先创建序列:

create sequence incr_stu_id_seq
minvalue 1
start with 1
increment by 1

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);

posted @ 2012-07-06 17:03  xzf007  阅读(140)  评论(0编辑  收藏  举报