一 建立表
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');

五 查看结果

相关文章: