oracle id 自动增长

--创建表

create table abc(
id number(4) not null primary key,
username varchar2(20) not null,
pwd varchar2(20) not null
);

--创建序列

create sequence abc_sequence
  increment by 1
  start with 1
  maxvalue 9999
  cycle nocache;

--创建触发器

create or replace trigger abc_trigger
       before insert on abc for each row
       begin
          select abc_sequence.nextval into:new.id from dual;
      end;

 

 

insert into abc(username, pwd) values('Tony', 'a');

insert into abc(username, pwd) values('Tony1', 'a');
select * from abc;

posted @ 2015-07-08 16:38  M-li  阅读(148)  评论(0编辑  收藏  举报