触发器编写,执行插入或update分别执行不同sql

CREATE OR REPLACE TRIGGER tg_voucher_name
AFTER insert or update on ab_voucherinfo
for each row
begin
IF INSERTING THEN
insert into DTL_TEST_LOG
(O_ID, BANK_ACC, UPDATE_TIME)
VALUES
(:NEW.ID,
:NEW.ID,
sysdate);
ELSE
insert into DTL_TEST_LOG
(O_ID, BANK_ACC, UPDATE_TIME)
VALUES
(:OLD.ID,
:NEW.ID,
sysdate);
END IF;
END;

或者根据值是否被更新或修改,记录操作

CREATE OR REPLACE TRIGGER update_bis_name
AFTER update on bis_acc_dtl
for each row
begin
IF UPDATING('BAL') THEN
IF :new.BAL != :old.BAL THEN
insert into DTL_TEST_LOG
(O_ID, BANK_ACC, LAST_BAL, NEW_BAL, VOUCHER_NUMBER,VOUCHER_NUMBER_OLD, UPDATE_TIME)
VALUES
(:OLD.ID,
:OLD.BANK_ACC,
:OLD.BAL,
:NEW.BAL,
:NEW.VOUCHER_NUMBER,
:OLD.VOUCHER_NUMBER,
sysdate);
END IF;
END IF;
END;

posted @ 2021-08-05 15:47  凉了记忆  阅读(177)  评论(0编辑  收藏  举报