⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap13_2.html

📁 Oracle资料大集合
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.middleware.html"><font face="verdana,helvetica" size="1" color="000000"><b>Middleware</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=12 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.components.html"><font face="verdana,helvetica" size="1" color="000000"><b>Components</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.operatingsystems.html"><font face="verdana,helvetica" size="1" color="000000"><b>Operating Systems</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.userinterfaces.html"><font face="verdana,helvetica" size="1" color="000000"><b>User Interfaces</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.groupwareandcollaboration1.html"><font face="verdana,helvetica" size="1" color="000000"><b>Groupware &amp; Collaboration</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.contentmanagement.html"><font face="verdana,helvetica" size="1" color="000000"><b>Content Management</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.productivityapplications1.html"><font face="verdana,helvetica" size="1" color="000000"><b>Productivity Applications</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.hardware1.html"><font face="verdana,helvetica" size="1" color="000000"><b>Hardware</b></font></td></tr><tr><td colspan="2"><img src="../../../images/dotclear.gif" width=6 height=12 alt="" border="0"></td></tr><tr><td><img src="../../../images/arrow.gif" width=10 height=17 alt="" border="0"></td><td><a href="http://www.itlibrary.com/reference/dir.funandgames1.html"><font face="verdana,helvetica" size="1" color="000000"><b>Fun &amp; Games</b></font></td></tr></table><!-- <IMG SRC="/images/leftnav.gif" WIDTH=111 HEIGHT=404 ALT="nav" border="0"  ISMAP USEMAP="#leftnav"> --><p><a href="http://www.earthweb.com/jobs/" target=new><IMG SRC="../../../images/dice-105x30.gif" WIDTH=105 HEIGHT=30 ALT="EarthWeb Direct" border="0"></a><a href="http://www.earthwebdirect.com/" target=new><IMG SRC="../../../images/earthwebdirect.gif" WIDTH=105 HEIGHT=30 ALT="EarthWeb Direct" border="0"></a><a href="http://www.fatbrain.com/home.html?from=UUX592" target=new><IMG SRC="../../../images/fatbrain.gif" WIDTH=105 HEIGHT=30 ALT="Fatbrain" border="0"></a><a href="http://auctions.earthweb.com" target=new><IMG SRC="../../../images/auctions_105x30.gif" WIDTH=105 HEIGHT=30 ALT="Auctions" border="0"></a><a href="http://www.supportsource.com" target=new><IMG SRC="../../../images/ss2000sneak2.gif" WIDTH=105 HEIGHT=30 ALT="Support Source Answers" border="0"></a><P><b><font face="verdana,helvetica" size="2">EarthWeb sites</FONT></b><br>  <FONT SIZE="1">  <a href="http://www.crossnodes.com"><font face="verdana,helvetica" size="1" color="000000">Crossnodes</font></a><br>  <a href="http://www.datamation.com"><font face="verdana,helvetica" size="1" color="000000">Datamation</font></a><br>  <a href="http://www.developer.com"><font face="verdana,helvetica" size="1" color="000000">Developer.com</FONT></A><br>  <a href="http://www.dice.com"><font face="verdana,helvetica" size="1" color="000000">DICE</font></a><br>  <a href="http://www.earthweb.com"><font face="verdana,helvetica" size="1" color="000000">EarthWeb.com</font></a><br>  <a href="http://www.earthwebdirect.com"><font face="verdana,helvetica" size="1" color="000000">EarthWeb Direct</font></a><br>  <a href="http://www.erphub.com"><font face="verdana,helvetica" size="1" color="000000">ERP Hub</font></a><br>  <a href="http://www.gamelan.com"><font face="verdana,helvetica" size="1" color="000000">Gamelan</font></a><br>  <a href="http://www.gocertify.com"><font face="verdana,helvetica" size="1" color="000000">GoCertify.com</font></a><br>  <a href="http://www.htmlgoodies.com"><font face="verdana,helvetica" size="1" color="000000">HTMLGoodies</font></a><br>  <a href="http://www.intranetjournal.com"><font face="verdana,helvetica" size="1" color="000000">Intranet Journal</font></a><br>  <a href="http://www.itknowledge.com"><font face="verdana,helvetica" size="1" color="000000">IT Knowledge</font></a><br>  <a href="http://www.itlibrary.com"><font face="verdana,helvetica" size="1" color="000000">IT Library</font></a><br>  <a href="http://www.javagoodies.com"><font face="verdana,helvetica" size="1" color="000000">JavaGoodies</font></a><br>  <a href="http://www.jars.com"><font face="verdana,helvetica" size="1" color="000000">JARS</font></a><br>  <a href="http://www.javascripts.com"><font face="verdana,helvetica" size="1" color="000000">JavaScripts.com</font></a><br>  <a href="http://www.opensourceit.com"><font face="verdana,helvetica" size="1" color="000000">open source IT</font></a><br>  <a href="http://www.roadcoders.com"><font face="verdana,helvetica" size="1" color="000000">RoadCoders</font></a><br>  <a href="http://www.Y2Kinfo.com"><font face="verdana,helvetica" size="1" color="000000">Y2K Info</font></a></FONT></td><!--End Left Navigation column --><!-- spacer column  --><TD width="40"><img src="../../../images/dotclear.gif" WIDTH="40" HEIGHT="1" border=0></TD><!--Begin Content Column --><TD VALIGN="TOP" width="500"><P><blockquote><p><b><font size="+1">13.2 How do I匲se column values within database triggers?</font></b><p><B>Problem</B><p>When I create database triggers, I need to use the values of the columns in the records being inserted, updated, or deleted. There are many times when I need to use both the values of columns before and after the operation. How do I use column values within database triggers?<p><B>Technique</B><p>The :NEW and :OLD pseudo-records are used to access new and old column values in a row trigger. You can access old column values of the record before the operation is performed by specifying the :OLD qualifier. The :NEW qualifier provides access to new column values of the record after the operation is performed. With an INSERT statement, the old column values are null, whereas with a DELETE statement, the new column values are null. The preceding colon is required when using the qualifiers in the trigger body. The colon is not allowed when using the qualifiers in the optional WHEN and REFERENCING clauses, as demonstrated in Step 3 of How-To 13.1. The REFERENCING option can be used to avoid name conflicts with qualifiers, if you have a table named as NEW or OLD or simply to increase code readability.<p><B>Steps</B><p><B>1.</B>	Run SQL*Plus and connect as the WAITE user account. Run CHP13_10.SQL, shown in <A HREF="image/13oht10.gif" TARGET="_blank">Figure 13.10</A>, which creates the sample table and data used in this How-To.<p>The sample table created by the script contains three columns and has database triggers created in the steps that follow. A sample record is created so the use of :OLD modifier can also be demonstrated with an existing record. Run the script to create the sample table and its sample record.<p><B>2.</B>	Run the CHP13_11.SQL file in SQL*Plus, as shown in <A HREF="image/13oht11.gif" TARGET="_blank">Figure 13.11</A>. The CREATE TRIGGER statement contained in the file creates a BEFORE UPDATE trigger referencing the new and old column values.<p>The :NEW and :OLD qualifiers are used to reference the columns in the table. Line 1 presents the required keywords and specifies the name of the trigger. Lines 2 and 3 specify the triggering statement and FOR EACH ROW option. The trigger will fire any time a record in the table is updated. Lines 5 through 10 use the :NEW and :OLD modifiers to display the values of the columns before and after the operation. Lines 5 through 7 display the values of the columns before the operation. Lines 8 through 10 show the values of the record after the operation.<p>The next step will display the new and old values of the columns in the existing record by executing an update statement on the table.<p><B>3.</B>	Run the CHP13_12.SQL file in SQL*Plus, as shown in <A HREF="image/13oht12.gif" TARGET="_blank">Figure 13.12</A>. The SERVEROUTPUT SQL*Plus variable is set to ON, to display the results of the operation. The UPDATE statement contained in the file modifies the record in the sample table, firing the BEFORE UPDATE trigger. The UPDATE statement modifies two of the three columns in the table. The new value of the third column will still remain the same as its old value.<p>The output of the operation displays both the new and old values of the column. A new value was even available for the column not modified by the operation.<p><B>How It Works</B><p>The :NEW qualifier allows the trigger code to reference the new value of columns in the table. The :OLD qualifier provides access to the column values before the operation is performed. Step 1 creates a sample table and record used by the example trigger. Step 2 creates a BEFORE UPDATE trigger displaying the value of the columns in the table both before and after the update. Step 3 executes an UPDATE statement on the table, causing the trigger to fire.<p><B>Comments</B><p>The :NEW and :OLD qualifiers are necessary to reference column values in triggers. Make sure you use the right value in your trigger. If you use a new value when you should have used an old value, you may see invalid results. The :NEW and :OLD qualifiers cannot be used with LONG and LONG RAW columns. Triggers should not be created depending on the order in which rows will be processed.<p><!-- </td></td></tr></table> --></td></td></tr></table><!-- begin footer information --><MAP NAME="footer"><AREA SHAPE=RECT COORDS="0,0,62,26" HREF="http://www.itlibrary.com/"><AREA SHAPE=RECT COORDS="62,0,135,26" HREF="http://www.developer.com/about/"><AREA SHAPE=RECT COORDS="135,0,199,26" HREF="http://www.itlibrary.com/search/"><AREA SHAPE=RECT COORDS="200,0,274,26" HREF="http://www.itlibrary.com/subscribe/"><AREA SHAPE=RECT COORDS="275,0,335,25" HREF="http://www.developer.com/contact/adinfo.html"><AREA SHAPE=RECT COORDS="335,0,417,25" HREF="http://www.developer.com/contact/"><AREA SHAPE=RECT COORDS="418,0,467,26" HREF="http://www.developer.com/about/faq.html"></MAP><P><table width="640" cellpadding="0" cellspacing="0" border="0"><tr><TD WIDTH="130"></TD><td width="468"><IMG SRC="../../../images/footer/footerfile.gif" ALT="footer nav" width="467" height="26" BORDER="0" usemap="#footer" ismap></td></tr><tr><TD WIDTH="130"></TD><td width="468"> <font face=arial,helvetica size="1"> Use of this site is subject certain <a href="http://www.developer.com/legal/">Terms &amp; Conditions.</a><br>Copyright (c) 1996-1999 <A HREF="http://www.earthweb.com/">EarthWeb, Inc.</A>.  All rights reserved.  Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited.<a href="http://www.earthweb.com/corporate/privacy.html">Please read our privacy policy for details.</a></td></tr></table></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -