145 lines
9.5 KiB
HTML
145 lines
9.5 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!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" lang="en-US" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="dc.language" scheme="rfc1766" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow"/>
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="keywords" content="SET transition-variable statement,
|
|
SET transition-variable, SQL statements, in statement, expression,
|
|
in SET transition-variable statement, NULL, DEFAULT, row-fullselect" />
|
|
<title>SET transition-variable</title>
|
|
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
|
|
<link rel="stylesheet" type="text/css" href="ic.css" />
|
|
</head>
|
|
<body>
|
|
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
|
|
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
|
|
|
|
|
|
<a name="settranv"></a>
|
|
<h2 id="settranv"><a href="rbafzmst02.htm#ToC_1355">SET transition-variable</a></h2><a id="idx3226" name="idx3226"></a><a id="idx3227" name="idx3227"></a>
|
|
<p>The SET transition-variable statement assigns values to new <var class="pv">transition-variable</var>s.</p>
|
|
<a name="wq1804"></a>
|
|
<h3 id="wq1804"><a href="rbafzmst02.htm#ToC_1356">Invocation</a></h3>
|
|
<p>This statement can only be used as an SQL statement in a BEFORE trigger.
|
|
It is an executable statement that cannot be dynamically prepared.</p>
|
|
<a name="wq1805"></a>
|
|
<h3 id="wq1805"><a href="rbafzmst02.htm#ToC_1357">Authorization</a></h3>
|
|
<p>If a <span class="italic">row-fullselect</span> is specified, see <a href="rbafzmstmark.htm#mark">fullselect</a> for an explanation of the authorization required for each subselect.</p>
|
|
<a name="wq1806"></a>
|
|
<h3 id="wq1806"><a href="rbafzmst02.htm#ToC_1358">Syntax</a></h3>
|
|
<a href="rbafzmstsettranv.htm#synsstv"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq1807"></a>
|
|
<div class="fignone" id="wq1807">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn394.htm"
|
|
border="0" /></span><a href="#skipsyn-393"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .-,-------------------------------------------------------------------------.
|
|
V |
|
|
>>-SET----+-<span class="italic">transition-variable</span>-- = --+-<span class="italic">expression</span>-+------------------------------+-+-><
|
|
| +-NULL-------+ |
|
|
| '-DEFAULT----' |
|
|
| .-,-------------------. .-,--------------. |
|
|
| V | V | (1) |
|
|
'-(----<span class="italic">transition-variable</span>-+--)-- = --(--+---+-<span class="italic">expression</span>-+-+------+--)-'
|
|
| +-NULL-------+ |
|
|
| '-DEFAULT----' |
|
|
| (2) |
|
|
'-<span><span class="italic">row-fullselect</span></span>----------'
|
|
|
|
</pre>
|
|
<a name="skipsyn-393" id="skipsyn-393"></a>
|
|
<a name="wq1808"></a>
|
|
<div class="notelisttitle" id="wq1808">Notes:</div>
|
|
<ol type="1">
|
|
<li>The number of <span class="italic">expression</span>s, NULLs, and DEFAULTs
|
|
must match the number of <span class="italic">transition-variable</span>s.</li>
|
|
<li>The number of columns in the select list must match the number of <span class="italic">transition-variable</span>s.</li>
|
|
</ol></div>
|
|
<a name="synsstv"></a>
|
|
<h3 id="synsstv"><a href="rbafzmst02.htm#ToC_1359">Description</a></h3>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">transition-variable</var></dt>
|
|
<dd>Identifies the column to be updated in the new row. A <var class="pv">transition-variable</var> must identify a column in the subject table of a trigger, optionally
|
|
qualified by a correlation name that identifies the new value. An OLD <var class="pv">transition-variable</var> must not be identified.
|
|
<p>A <var class="pv">transition-variable</var> must not be identified more than once in the same SET transition-variable
|
|
statement.</p>
|
|
<p>The data type of each <var class="pv">transition-variable</var> must be
|
|
compatible with its corresponding result column. Values are assigned to <var class="pv">transition-variable</var>s according to the assignment rules to a column. For
|
|
more information see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression</var> </dt><a id="idx3228" name="idx3228"></a>
|
|
<dd>Specifies the new value of the <var class="pv">transition-variable</var>. The <var class="pv">expression</var> is any expression of the type described in <a href="rbafzmstch2expr.htm#ch2expr">Expressions</a>. The expression cannot include an aggregate function.
|
|
<p>An <var class="pv">expression</var> may contain references to OLD and NEW <var class="pv">transition-variable</var>s. If the CREATE TRIGGER statement contains both OLD and NEW clauses,
|
|
references to <var class="pv">transition-variable</var>s must be qualified by the <var class="pv">correlation-name</var>.</p>
|
|
</dd>
|
|
<dt class="bold">NULL</dt><a id="idx3229" name="idx3229"></a>
|
|
<dd>Specifies the null value. NULL can only be specified for nullable columns.
|
|
</dd>
|
|
<dt class="bold">DEFAULT</dt><a id="idx3230" name="idx3230"></a>
|
|
<dd>Specifies that the default value of the column associated
|
|
with the <var class="pv">transition-variable</var> will be used. DEFAULT is not allowed
|
|
if the column is an IDENTITY column or has a ROWID data type.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">row-fullselect</var></dt><a id="idx3231" name="idx3231"></a>
|
|
<dd>A fullselect that returns a single result row. The result column values
|
|
are assigned to each corresponding <var class="pv">transition-variable</var>. If the result
|
|
of the fullselect is no rows, then null values are assigned. An error is returned
|
|
if there is more than one row in the result.
|
|
</dd>
|
|
</dl>
|
|
<a name="wq1810"></a>
|
|
<h3 id="wq1810"><a href="rbafzmst02.htm#ToC_1360">Notes</a></h3>
|
|
<dl class="parml">
|
|
<dt class="bold">Multiple assignments</dt>
|
|
<dd>If more than one assignment is included in the same SET transition-variable
|
|
statement, all <span class="italic">expression</span>s are evaluated before the
|
|
assignments are performed. Thus, references to <var class="pv">transition-variable</var>s
|
|
in an expression are always the value of the <var class="pv">transition-variable</var> prior
|
|
to any assignment in the single SET statement.
|
|
</dd>
|
|
</dl>
|
|
<a name="wq1811"></a>
|
|
<h3 id="wq1811"><a href="rbafzmst02.htm#ToC_1361">Examples</a></h3>
|
|
<p><span class="italic">Example 1:</span> Ensure that the salary column is never
|
|
greater than 50000. If the new value is greater than 50000, set it to 50000. </p>
|
|
<pre class="xmp"><span class="bold">CREATE TRIGGER</span> LIMIT_SALARY
|
|
<span class="bold">BEFORE INSERT ON</span> EMPLOYEE
|
|
<span class="bold">REFERENCING NEW AS</span> NEW_VAR
|
|
<span class="bold">FOR EACH ROW MODE DB2SQL</span>
|
|
<span class="bold">WHEN (</span>NEW_VAR.SALARY > 50000<span class="bold">)</span>
|
|
<span class="bold">BEGIN ATOMIC</span>
|
|
<span class="bold">SET</span> NEW_VAR.SALARY <span class="bold">=</span> 50000;
|
|
<span class="bold">END</span> </pre>
|
|
<p><span class="italic">Example 2:</span> When the job title is updated, increase
|
|
the salary based on the new job title. Assign the years in the position to
|
|
0. </p>
|
|
<pre class="xmp"><span class="bold">CREATE TRIGGER</span> SET_SALARY
|
|
<span class="bold">BEFORE UPDATE OF</span> JOB <span class="bold">ON</span> STAFF
|
|
<span class="bold">REFERENCING OLD AS</span> OLD_VAR
|
|
<span class="bold">NEW AS</span> NEW_VAR
|
|
<span class="bold">FOR EACH ROW MODE DB2SQL</span>
|
|
<span class="bold">BEGIN ATOMIC</span>
|
|
<span class="bold">SET (</span>NEW_VAR.SALARY, NEW_VAR.YEARS<span class="bold">) =</span>
|
|
<span class="bold">(</span>OLD_VAR.SALARY * <span class="bold">CASE </span>NEW_VAR.JOB
|
|
<span class="bold">WHEN</span> 'Sales' <span class="bold">THEN</span> 1.1
|
|
<span class="bold">WHEN</span> 'Mgr' <span class="bold">THEN</span> 1.05
|
|
<span class="bold">ELSE</span> 1 <span class="bold">END</span> ,0<span class="bold">)</span>;
|
|
<span class="bold">END</span> </pre>
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstsettraj.htm">Previous Page</a> | <a href="rbafzmstsetinto.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
|
|
<a href="rbafzmstindex.htm#index">Index</a> ]
|
|
|
|
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
|
|
</body>
|
|
</html>
|