I have created a very simple trigger in a certain table (e.g. TABLE_TRIGGER) that will call a procedure (handles all the logic). This table has a column (e.g. AUDITID) which I would like to exclude in the trigger function, I mean, if update is only done in AUDITID column, the procedure should not be executed.
Below is the trigger:
CREATE OR REPLACE TRIGGER TABLE_TRIGGER_FUNCTION
AFTER INSERT OR UPDATE
ON TABLE_TRIGGER
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
-- procedure();
END;
Is there other way to do it, other than the one suggested here: Oracle: excluding updates of one column for firing a trigger
The answer provided here is the one I would like to have Fire trigger on updates (excluding certain fields change) but I am not sure if this is something that can also be done using Oracle PL/SQL syntax.
By the way, I have tried using the following WHEN statement by excluding the AUDITID column but the trigger did not work at all and the procedure was not executed.
WHEN (NEW.FILEID != OLD.FILEID OR
NEW.DESCRIPTION != OLD.DESCRIPTION OR
NEW.IMAGEID != OLD.IMAGEID OR
NEW.STATETYPEID != OLD.STATETYPEID OR
NEW.ACCESSLEVELID != OLD.ACCESSLEVELID OR
NEW.FILETYPEID != OLD.FILETYPEID)
I'm not aware of a way to exclude a column from an update trigger, but you could define a list of columns it would fire on, and list all the columns except the auditid:
CREATE OR REPLACE TRIGGER TABLE_TRIGGER_FUNCTION
AFTER INSERT OR UPDATE
OF FILEID, -- Field list starts here...
DESCRIPTION,
IMAGEID,
STATETYPEID,
ACCESSLEVELID,
ACCESSLEVELID,
FILETYPEID -- ... and ends here
ON TABLE_TRIGGER
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
-- procedure();
END;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With