oracle主键自增长

这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下:

  create table simon_example

  (

  id number(4) not null primary key,

  name varchar2(25)

  )

  -- 建立序列:

  -- Create sequence

  create sequence SIMON_SEQUENCE

  minvalue 1

  maxvalue 999999999999999999999999999

  start with 1

  increment by 1

  cache 20;

  -- 建立触发器

  create trigger "simon_trigger" before

  insert on simon_example for each row when(new.id is null)

  begin

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

  end;

posted on 2014-04-17 09:39  锟斤拷锟斤拷  阅读(164)  评论(0编辑  收藏  举报

导航