Oracle设置主键自增长
第一步:为表设置主键
第二步:新建序列
CREATE SEQUENCE SQ.SEQ_INCREASE
START WITH 12
MAXVALUE 999
MINVALUE 0
INCREMENT BY 1
NOCYCLE
NOCACHE
NOORDER;
第三步:创建触发器
CREATE OR REPLACE TRIGGER SQ.tg_depid_increase
BEFORE INSERT
ON SQ.SYS_DEPARTMENT //表名
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
WHEN (
New.id is null
)
BEGIN
select seq_increase.nextval into :New.id from dual;
END tg_depid_increase;