oracle自增ID实现

创建序列
create sequence SID_TB_PUBLIC_USER
minvalue 1
maxvalue 999999999999
start with 1
increment by 1
cache 20;

SID_TB_PUBLIC_USER序列名称


创建触发器
CREATE TRIGGER TRI_TB_PUBLIC_USER BEFORE

INSERT ON TB_PUBLIC_USER FOR EACH ROW WHEN (new.PUBLICUSERID is null)

begin

select SID_TB_PUBLIC_USER.nextval into :new.PUBLICUSERID from dual;

end;
TRI_TB_PUBLIC_USER触发器名称
TB_PUBLIC_USER表名
new.PUBLICUSERID表中自增ID,必须用new.来开头
SID_TB_PUBLIC_USER序列名

你可能感兴趣的:(java,oracle,cache)