createtableTEST ( ID intPRIMARYKEY, test1 varchar2(20), test2 varchar2(20), test3 varchar2(20) )
create sequence SEQ_TEST minvalue 1 --最小值 maxvalue 999999999999999999999999999 --最大值 start with 1 ---從1開始 increment by 1 ---每次加1 nocycle --一直累加,不循環 nocache;
CREATE OR REPLACE TRIGGER tg_test //test表名,id主鍵名,seq_test.nextval序列 BEFORE INSERT ON test FOR EACH ROW WHEN (new.id is null) begin select seq_test.nextval into:new.id from dual; end;
//------------------觸發器樣式 CREATE OR REPLACE TRIGGER TRI_SCORE BEFORE INSERT OR UPDATE ON XUANKE FOR EACH ROW BEGIN //如果score為空,則令score=0 IF :new.SCORE IS NULL THEN :new.SCORE:= 0; END IF; END;