Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\applications\em\em\online_help\tdddg\tdddg_triggers001.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <script src="./callback.js" type="text/javascript"></script> <noscript>Your browser does not support JavaScript. This help page requires JavaScript to render correctly.</noscript> </head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta name="generator" content="Oracle DARB XHTML Converter (Mode = ohj/ohw) - Version 5.1.1 Build 005" /> <meta name="date" content="2009-04-21T9:46:25Z" /> <meta name="robots" content="noarchive" /> <meta name="doctitle" content="About Triggers" /> <meta name="relnum" content="11g Release 2 (11.2)" /> <meta name="partnum" content="E10766-01" /> <link rel="copyright" href="./dcommon/html/cpyr.htm" title="Copyright" type="text/html" /> <link rel="stylesheet" href="./dcommon/css/blafdoc.css" title="Oracle BLAFDoc" type="text/css" /> <link rel="contents" href="toc.htm" title="Contents" type="text/html" /> <link rel="prev" href="tdddg_triggers.htm" title="Previous" type="text/html" /> <link rel="next" href="tdddg_triggers002.htm" title="Next" type="text/html" /> <title>About Triggers</title> </head> <body> <div class="zz-skip-header"><a href="#BEGIN">Skip Headers</a></div> <table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%"> <col width="86%" /> <col width="*" /> <tr valign="bottom"> <td align="left"></td> <td align="center"><a href="tdddg_triggers.htm"><img width="24" height="24" src="./dcommon/gifs/leftnav.gif" alt="Previous" /><br /> <span class="icon">Previous</span></a> </td> <td align="center"><a href="tdddg_triggers002.htm"><img width="24" height="24" src="./dcommon/gifs/rightnav.gif" alt="Next" /><br /> <span class="icon">Next</span></a></td> </tr> </table> <p><a id="BABIHIHH" name="BABIHIHH"></a><a id="TDDDG51000" name="TDDDG51000"></a></p> <div class="sect1"><!-- infolevel="all" infotype="General" --> <h1>About Triggers</h1> <a name="BEGIN" id="BEGIN"></a> <p>A <a id="sthref533" name="sthref533"></a><span class="bold">trigger</span> is a PL/SQL unit that is stored in the database and (if it is in the enabled state) automatically executes ("fires") in response to a specified event.</p> <p>A trigger has this structure:</p> <pre xml:space="preserve" class="oac_no_warn"> TRIGGER <span class="italic">trigger_name</span> <span class="italic">triggering_event</span> [ <span class="italic">trigger_restriction</span> ] BEGIN <span class="italic">triggered_action</span>; END; </pre> <p>The <code><span class="codeinlineitalic">trigger_name</span></code> must be unique for triggers in the schema. A trigger can have the same name as another kind of object in the schema (for example, a table); however, Oracle recommends using a naming convention that avoids confusion.</p> <p>If the trigger is in the <a id="sthref534" name="sthref534"></a><a id="sthref535" name="sthref535"></a><span class="bold">enabled</span> state, the <code><span class="codeinlineitalic">triggering_event</span></code> causes the database to execute the <code><span class="codeinlineitalic">triggered_action</span></code> if the <code><span class="codeinlineitalic">trigger_restriction</span></code> is either <code>TRUE</code> or omitted. The <code><span class="codeinlineitalic">triggering_event</span></code> is associated with either a table, a view, a schema, or the database, and it is one of these:</p> <ul> <li> <p><a id="sthref536" name="sthref536"></a>DML statement (described in <a href="tdddg_dml001.htm#BCGBGBIE">"About Data Manipulation Language (DML) Statements"</a>)</p> </li> <li> <p><a id="sthref537" name="sthref537"></a>DDL statement (described in <a href="tdddg_objects001.htm#CIHGAJDJ">"About Data Definition Language (DDL) Statements"</a>)</p> </li> <li> <p>Database operation (<code>SERVERERROR</code>, <code>LOGON</code>, <code>LOGOFF</code>, <code>STARTUP</code>, or <code>SHUTDOWN</code>)</p> </li> </ul> <p>If the trigger is in the <a id="sthref538" name="sthref538"></a><a id="sthref539" name="sthref539"></a><span class="bold">disabled</span> state, the <code><span class="codeinlineitalic">triggering_event</span></code> does not cause the database to execute the <code><span class="codeinlineitalic">triggered_action</span></code>, even if the <code><span class="codeinlineitalic">trigger_restriction</span></code> is <code>TRUE</code> or omitted.</p> <p>By default, a trigger is created in the enabled state. You can disable an enabled trigger, and enable a disabled trigger.</p> <p>Unlike a subprogram, a trigger cannot be invoked directly. A trigger is invoked only by its triggering event, which can be caused by any user or application. You might be unaware that a trigger is executing unless it causes an error that is not handled properly.</p> <p>A <a id="sthref540" name="sthref540"></a><a id="sthref541" name="sthref541"></a><span class="bold">simple trigger</span> can fire at exactly one of these <a id="sthref542" name="sthref542"></a><a id="sthref543" name="sthref543"></a><span class="bold">timing points</span>:</p> <ul> <li> <p>Before the triggering event executes (<a id="sthref544" name="sthref544"></a><a id="sthref545" name="sthref545"></a>statement-level <a id="sthref546" name="sthref546"></a><a id="sthref547" name="sthref547"></a><code>BEFORE</code> trigger)</p> </li> <li> <p>After the triggering event executes (statement-level <a id="sthref548" name="sthref548"></a><a id="sthref549" name="sthref549"></a><code>AFTER</code> trigger)</p> </li> <li> <p>Before each row that the event affects (<a id="sthref550" name="sthref550"></a><a id="sthref551" name="sthref551"></a>row-level <code>BEFORE</code> trigger)</p> </li> <li> <p>After each row that the event affects (row-level <code>AFTER</code> trigger)</p> </li> </ul> <p>A <a id="sthref552" name="sthref552"></a><a id="sthref553" name="sthref553"></a><span class="bold">compound trigger</span> can fire at multiple timing points. For information about compound triggers, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS2005','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> <p>An <a id="sthref554" name="sthref554"></a><a id="sthref555" name="sthref555"></a><code><span class="codeinlinebold">INSTEAD</span></code> <code><span class="codeinlinebold">OF</span></code> <span class="bold">trigger</span> is defined on a view, and its triggering event is a DML statement. Instead of executing the DML statement, Oracle Database executes the <code>INSTEAD</code> <code>OF</code> trigger. For more information, see <a href="tdddg_triggers006.htm#BABECIAE">"Creating an INSTEAD OF Trigger"</a>.</p> <p>A <a id="sthref556" name="sthref556"></a><a id="sthref557" name="sthref557"></a><span class="bold">system trigger</span> is defined on a schema or the database. A trigger defined on a schema fires for each event associated with the owner of the schema (the current user). A trigger defined on a database fires for each event associated with all users.</p> <p>One use of triggers is to enforce business rules that apply to all client applications. For example, suppose that data added to the <code>EMPLOYEES</code> table must have a certain format, and that many client applications can add data to this table. A trigger on the table can ensure the proper format of all data added to it. Because the trigger executes whenever any client adds data to the table, no client can circumvent the rules, and the code that enforces the rules can be stored and maintained only in the trigger, rather than in every client application. For other uses of triggers, see <a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS99986','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a>.</p> <div class="helpinfonotealso"> <h2>Related Topics</h2> <p><a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS020','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a></p> <p><a href="tdddg_triggers.htm#BABIEDEF">Using Triggers</a></p> </div> </div> <!-- class="sect1" --> <!-- Start Footer --> <div class="footer"> <table class="simple oac_no_warn" summary="" cellspacing="0" cellpadding="0" width="100%"> <col width="86%" /> <col width="*" /> <tr> <td align="left"><span class="copyrightlogo">Copyright © 1996, 2009, Oracle and/or its affiliates. All rights reserved.</span><br /> <a href="./dcommon/html/cpyr.htm"><span class="copyrightlogo">Legal Notices</span></a></td> <td align="center"><a href="tdddg_triggers.htm"><img width="24" height="24" src="./dcommon/gifs/leftnav.gif" alt="Previous" /><br /> <span class="icon">Previous</span></a> </td> <td align="center"><a href="tdddg_triggers002.htm"><img width="24" height="24" src="./dcommon/gifs/rightnav.gif" alt="Next" /><br /> <span class="icon">Next</span></a></td> </tr> </table> </div> <!-- class="footer" --> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de