CREATE OR REPLACE TRIGGER AUD_JDTL_TRG
BEFORE INSERT OR UPDATE OR DELETE ON TEST.JDTL
REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
DECLARE
INFO VARCHAR2(100);
BEGIN
SELECT SYS_CONTEXT('USERENV','OS_USER')||'-'||SYS_CONTEXT('USERENV','IP_ADDRESS') INTO INFO FROM DUAL;
IF INSERTING THEN
INSERT INTO AUD_TEST.JDTL(TRNNO,SR,CHCODE,NARRATION,DR,CR,CHANGEON,DML,ADDRESS,USER_NAME)
VALUES(:NEW.TRNNO,:NEW.SR,:NEW.CHCODE,:NEW.NARRATION,:NEW.DR,:NEW.CR,SYSDATE,'I',INFO,USER);
ELSIF UPDATING THEN
INSERT INTO AUD_TEST.JDTL(TRNNO,SR,CHCODE,NARRATION,DR,CR,CHANGEON,DML,ADDRESS,USER_NAME)
VALUES(:NEW.TRNNO,:NEW.SR,:NEW.CHCODE,:NEW.NARRATION,:NEW.DR,:NEW.CR,SYSDATE,'U' , INFO,USER);
ELSIF DELETING THEN
INSERT INTO AUD_TEST.JDTL(TRNNO,SR,CHCODE,NARRATION,DR,CR,CHANGEON,DML,ADDRESS,USER_NAME)
VALUES(:OLD.TRNNO,:OLD.SR,:OLD.CHCODE,:OLD.NARRATION,:OLD.DR,:OLD.CR,SYSDATE,'D' , INFO,USER);
END IF;
END;
我手动为架构包含的所有表编写此触发器,但我想为所有表编写此触发器,是否可以使用循环或任何其他方式编写,它用于包含所有数据的审计目的当用户更新,删除或插入时 是否有任何其他方式形成用户保存在“user_name”列(实际上是一个全局用户)