Oracle自动增长字段

一 建立表
create table ZH_TEST

   ID NUMBER not null, 
   NAME VARCHAR2(20)
)

二 建立sequence
create sequence ZH_AUTOINC
minvalue 1
start with 1
increment by 1
nocache;

三 建立触发器
create or replace trigger INSERT_FOR_AUTOINC
   before insert on ZH_TEST   
   for each row
declare
  -- local variables here
begin
   select ZH_AUTOINC.nextval into:new.ID from dual;
end insert_for_autoinc;

四 用insert语句测试
insert into ZH_TEST(NAME) values ('z5');

五 查看结果

posted on 2007-07-24 16:03  小乔的闺房  阅读(789)  评论(0编辑  收藏  举报

导航