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

oracle中使用序列实现id自增

2010-09-01 13:47 489 查看
conn scott/tiger@db890
1、创建序列
create sequence foo_id_seq
nocycle
maxvalue 9999999999
start with 1;
2、使用触发器自增
drop table foo;
create table foo(
  id number primary key,
  data varchar2(100));

create or replace trigger foo_id_pk
  before insert
    on foo
    for each row
begin
  select foo_seq.nextval into :new.id from dual;
end;
/

insert into foo(data)
  values('Chirstopher');
insert into foo(id,data)
  values(5,'Sean');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle insert table each