Title: RE: Trigger Firing and Execution of Body Code

brad,

you have got it right .... but to prove your assumptions .. it is very easy ...

alter session set events '10046 trace name context forever, level 4'
/
run some dml on the table
alter session set events '10046 trace name context off'
/

Then look through trace file, it will show you the logic used to fire or skip the trigger execution.

Raj
--------------------------------------------------------------------------------
Rajendra dot Jamadagni at nospamespn dot com
All Views expressed in this email are strictly personal.
QOTD: Any clod can have facts, having an opinion is an art !


-----Original Message-----
From: Odland, Brad [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 24, 2003 11:10 AM
To: Multiple recipients of list ORACLE-L
Subject: Trigger Firing and Execution of Body Code


Rich noticed at a large number of executions for a trigger on a table the
header looks like this and now we are a bit confused. Consider the
following:


AFTER INSERT OR UPDATE ON BLAH.PARTMASTER
 FOR EACH ROW
 WHEN (NEW.commodity_code != OLD.commodity_code OR OLD.commodity_code IS
NULL)
BEGIN

(Trigger with many executions)


ON another trigger with a OF clause

 AFTER INSERT OR UPDATE OF commodity_code ON blah.partmaster
FOR EACH ROW
WHEN (new.commodity_code != old.commodity_code)
BEGIN

(Trigger with few executions)


Is the following statement true?

A trigger can fire but will not always execute the code in the body.

I believe it is based on the examples above. The top trigger will fire on
every insert and update of any column in the table but will not run code in
the body and just exit thus incrementing an execution stat. The second
trigger will execute when the commodity code column is updated. Keep in mind
I am saying here EXECUTE not FIRE the BODY.

So a trigger is said to execute when the condition for the trigger (AFTER
INSERT OR UPDATE in this case) is met.

The interesting issue to is that the first trigger grabs 8k of memory every
time it fires and it has executed 900,000 time in the past month and a half.
I suspect that a trigger is a continuous package of compiled code that when
the initial condition of ON INSERT OR UPDATE ON TABLE executes the trigger
code. The WHEN clause in the code is simple logical branching condition like
an IF statement. When the condition is not met it skips the body and
continues to the end resulting in the trigger "executing" or "firing" even
though the body was not processed.

questions, comments, suggestions?
thoughts, feelings, ideas?
statements, opinions, conjecture?
Am I nuts, should I care?


Brad O.
--
Please see the official ORACLE-L FAQ: http://www.orafaq.net
--
Author: Odland, Brad
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

*********************************************************************This e-mail 
message is confidential, intended only for the named recipient(s) above and may 
contain information that is privileged, attorney work product or exempt from 
disclosure under applicable law. If you have received this message in error, or are 
not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 
and delete this e-mail message from your computer, Thank 
you.*********************************************************************1

Reply via email to