自定义序列(sequence):
CREATE SEQUENCE example_sequence
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
NOCACHE -- 不建缓冲区
创建触发器:
--例1
CREATE TRIGGER example_triger BEFORE
INSERT ON example FOR EACH ROW WHEN (new.id is null)--只有在id为空时,启动该触发器生成id号
begin
select example_sequence.nextval into :new.id from dual;
end;
--例2
CREATE OR REPLACE TRIGGER SPM_PRO_PLAN_ID_TRIGGER
BEFORE INSERT ON SPM_PRO_PLAN
FOR EACH ROW ENABLE
beginselect SPM_PRO_PLAN_ID_SEQUENCE.NEXTVAL into :new.ID from dual;
end;