自定義序列(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;