Oracle 通过Sequence和触发器实现ID自动增涨
Create Sequence reader_sequence MINVALUE 1 MAXVALUE 999999999999999999999999999 START WITH 1 INCREMENT BY 1 CACHE 20;
?
2.创建一张表
-- 权限create table privilege ( id number(19,0) not null,--流水号 name varchar2(255 char) not null unique,--权限名称 description varchar2(255 char) null,--权限描述 code varchar2(64 char) not null unique, -- 代码 feature varchar2(64 char) not null, -- 特性名称 module varchar2(64 char) not null -- 模块名称 primary key (id));
?
?3.给表增加触发器,自动获得ID
?
create or replace trigger privilege_trigger before insert on privilege referencing old as old new as new for each row begin select reader_sequence.nextval into :new.id from dual; end;
?