Re: Triggers
From: Mark D Powell <Mark.Powell2_at_hp.com>
Date: Thu, 8 Jul 2010 13:06:55 -0700 (PDT)
Message-ID: <1337957a-5045-4231-bda5-31b1991d460a_at_j8g2000yqd.googlegroups.com>
On Jul 8, 2:49 pm, The Magnet <a..._at_unsu.com> wrote:
> Ok, probably a simple question but, say I have an after update on a
> table of maybe 20 columns, for each row.
>
> If a column in the source table is updated I should use the :NEW,
> right? And if it is not updated I assume I should use the :OLD?
>
> I guess what I am getting is I do not know which columns are updated,
> so, how do I code the trigger to know which to use, :NEW or :OLD,
> since not all columns will be updated?
Date: Thu, 8 Jul 2010 13:06:55 -0700 (PDT)
Message-ID: <1337957a-5045-4231-bda5-31b1991d460a_at_j8g2000yqd.googlegroups.com>
On Jul 8, 2:49 pm, The Magnet <a..._at_unsu.com> wrote:
> Ok, probably a simple question but, say I have an after update on a
> table of maybe 20 columns, for each row.
>
> If a column in the source table is updated I should use the :NEW,
> right? And if it is not updated I assume I should use the :OLD?
>
> I guess what I am getting is I do not know which columns are updated,
> so, how do I code the trigger to know which to use, :NEW or :OLD,
> since not all columns will be updated?
If you use the :old or :new tags depends on what you are trying to accomplish.
If you want to know if a specific column value changed you can
If :old.column_a <> :new.column_a
then change_logic
else no_change_logic
end if;
Often you just refer to the :old columns to build a history/audit row or refer to the :new columns to be used in updating a related table.
HTH -- Mark D Powell -- Received on Thu Jul 08 2010 - 15:06:55 CDT