Oracle创建序列和触发器,实现插入数据后id自增

--1.创建表:  t_ebuilder_regcategory

--2.创建序列: EBUILDER_REGCATEGORY_SEQ

  create sequence EBUILDER_REGCATEGORY_SEQ

  minvalue 1

  maxvalue 9999999999999999999999

  start with 1
  increment by 1

  cache 20 ;

--3.创建触发器: ebuilder_regcategory_tg

  create or replace trigger ebuilder_regcategory_tg before insert on t_ebuilder_regcategory for each row

  when (new.id is null)

  begin select EBUILDER_REGCATEGORY_SEQ.NEXTVAL into :new.id from dual; end;

  

 

你可能感兴趣的:(笔记)