I have an AFTER INSERT OR UPDATE OR DELETE trigger that I write to store every revision of a record that appears in a specific table, copying the INSERT and UPDATE :NEW values ββto the mirror table, and for DELETE values :OLD .
I could significantly clutter my code by conditionally passing a record :NEW or :OLD to a procedure that would then insert into my history table. Unfortunately, I cannot find a way to transfer the whole record :OLD or :NEW .
Am I missing something or is there no way to avoid listing all the columns :NEW and :OLD when I call my insert procedure?
I want to do the following:
DECLARE PROCEDURE LOCAL_INSERT(historyRecord in ACCT.ACCOUNTS%ROWTYPE) IS BEGIN INSERT INTO ACCT.ACCOUNTS_HISTORY (ID, NAME, DESCRIPTION, DATE) VALUES (historyRecord.ID, historyRecord.NAME, historyRecord.DESCRIPTION, SYSDATE); END; BEGIN IF INSERTING OR UPDATING THEN LOCAL_INSERT(:NEW); ELSE
But I am stuck with this:
DECLARE PROCEDURE LOCAL_INSERT(id in ACCT.ACCOUNTS.ID%TYPE, name in ACCT.ACCOUNTS.NAME%TYPE, description in ACCT.ACCOUNTS.DESCRIPTION%TYPE) IS BEGIN INSERT INTO ACCT.ACCOUNTS_HISTORY (ID, NAME, DESCRIPTION, DATE) VALUES (id, name, description, SYSDATE); END; BEGIN IF INSERTING OR UPDATING THEN LOCAL_INSERT(:NEW.ID, :NEW.NAME, :NEW.DESCRIPTION); ELSE
Okay, so this does not look like a big difference, but this is just an example with three columns, not tens.
oracle plsql triggers stored-procedures
aw crud
source share