Edit D:\app\Administrator\product\11.2.0\dbhome_1\oc4j\j2ee\oc4j_applications\applications\em\em\online_help\tdddg\tdddg_triggers006.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="Creating an INSTEAD OF Trigger" /> <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_triggers005.htm" title="Previous" type="text/html" /> <link rel="next" href="tdddg_triggers007.htm" title="Next" type="text/html" /> <title>Creating an INSTEAD OF Trigger</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_triggers005.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_triggers007.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="BABECIAE" name="BABECIAE"></a><a id="TDDDG52800" name="TDDDG52800"></a></p> <div class="sect2"><!-- infolevel="all" infotype="General" --> <h1>Creating an INSTEAD OF Trigger</h1> <a name="BEGIN" id="BEGIN"></a> <p>A view presents the output of a query as a table. If you want to change a view as you would change a table, you must create <a id="sthref581" name="sthref581"></a><a id="sthref582" name="sthref582"></a><a id="sthref583" name="sthref583"></a><a id="sthref584" name="sthref584"></a><code>INSTEAD</code> <code>OF</code> triggers. Instead of changing the view, they change the underlying tables.</p> <p>For example, consider the view <code>EMP_LOCATIONS</code>, whose <code>NAME</code> column is created from the <code>LAST_NAME</code> and <code>FIRST_NAME</code> columns of the <code>EMPLOYEES</code> table:</p> <pre xml:space="preserve" class="oac_no_warn"> CREATE VIEW EMP_LOCATIONS AS SELECT e.EMPLOYEE_ID, <span class="bold">e.LAST_NAME || ', ' || e.FIRST_NAME NAME</span>, d.DEPARTMENT_NAME DEPARTMENT, l.CITY CITY, c.COUNTRY_NAME COUNTRY FROM <span class="bold">EMPLOYEES e</span>, DEPARTMENTS d, LOCATIONS l, COUNTRIES c WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID AND d.LOCATION_ID = l.LOCATION_ID AND l.COUNTRY_ID = c.COUNTRY_ID ORDER BY LAST_NAME; </pre> <p>To update <code>EMP_LOCATIONS</code>.<code>NAME</code>, you must update <code>EMPLOYEES</code>.<code>LAST_NAME</code> and <code>EMPLOYEES</code>.<code>FIRST_NAME</code>. This is what the <code>INSTEAD</code> <code>OF</code> trigger in the following example does.</p> <p>This trigger is part of the <a id="sthref585" name="sthref585"></a>sample application that the tutorials and examples in this document show how to develop and deploy.</p> <p><code>NEW</code> and <code>OLD</code> are <span class="bold">pseudorecords</span> that the PL/SQL run-time engine creates and populates whenever a row-level trigger fires. <code>OLD</code> and <code>NEW</code> store the original and new values, respectively, of the record being processed by the trigger. They are called pseudorecords because they do not have all properties of PL/SQL records.</p> <div class="example"><a id="BABBFAGD" name="BABBFAGD"></a><a id="TDDDG251" name="TDDDG251"></a> <p class="titleinexample">Creating an INSTEAD OF Trigger</p> <pre xml:space="preserve" class="oac_no_warn"> CREATE OR REPLACE TRIGGER update_name_view_trigger <span class="bold">INSTEAD OF UPDATE ON emp_locations</span> BEGIN <span class="bold">UPDATE employees SET</span> <span class="bold">first_name = substr( :NEW.name, instr( :new.name, ',' )+2),</span> <span class="bold">last_name = substr( :NEW.name, 1, instr( :new.name, ',')-1)</span> <span class="bold">WHERE employee_id = :OLD.employee_id;</span> END; </pre></div> <!-- class="example" --> <div class="helpinfonotealso"> <h2>Related Topics</h2> <p><a href="javascript:open('http://www.oracle.com/pls/db112/lookup?id=LNPLS20041','newWindow').focus()"><span class="italic">Oracle Database PL/SQL Language Reference</span></a></p> <p><a href="tdddg_triggers002.htm#BABDAGJJ">Creating Triggers</a></p> </div> </div> <!-- class="sect2" --> <!-- 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_triggers005.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_triggers007.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