132 lines
8.0 KiB
HTML
132 lines
8.0 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="assignment-statement, SQL-control-statement,
|
||
|
SQL statements" />
|
||
|
<title>assignment-statement</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="assignstmt"></a>
|
||
|
<h2 id="assignstmt"><a href="rbafzmst02.htm#ToC_1410">assignment-statement</a></h2><a id="idx3328" name="idx3328"></a><a id="idx3329" name="idx3329"></a>
|
||
|
<p>The assignment-statement assigns a value to an SQL parameter or SQL variable.</p>
|
||
|
<a name="wq1849"></a>
|
||
|
<h3 id="wq1849"><a href="rbafzmst02.htm#ToC_1411">Syntax</a></h3>
|
||
|
<a href="rbafzmstassignstmt.htm#synassignment"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
||
|
<p>
|
||
|
</p>
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn406.htm"
|
||
|
border="0" /></span><a href="#skipsyn-405"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>>>-+--------+--SET--<span class="italic">assignment-clause</span>--------------------------><
|
||
|
'-<span class="italic">label:</span>-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-405" id="skipsyn-405"></a><p class="indatacontent">
|
||
|
</p>
|
||
|
<a name="wq1850"></a>
|
||
|
<div class="fignone" id="wq1850">
|
||
|
<p><span class="bold">assignment-clause:</span></p>
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn407.htm"
|
||
|
border="0" /></span><a href="#skipsyn-406"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a> .-,-----------------------------------------------------------------------.
|
||
|
V |
|
||
|
>>---+-+-<span class="italic">SQL-parameter-name</span>-+-- = --+-<span class="italic">expression</span>-+-------------------------+-+-><
|
||
|
| '-<span class="italic">SQL-variable-name</span>--' +-NULL-------+ |
|
||
|
| '-DEFAULT----' |
|
||
|
| .-,----------------------. .-,--------------. |
|
||
|
| V | V | |
|
||
|
'-(----+-<span class="italic">SQL-parameter-name</span>-+-+--)-- = --+-(----+-<span class="italic">expression</span>-+-+--)-+-'
|
||
|
'-<span class="italic">SQL-variable-name</span>--' | +-NULL-------+ |
|
||
|
| '-DEFAULT----' |
|
||
|
'-<span><span class="italic">row-fullselect</span></span>-----------'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-406" id="skipsyn-406"></a></div>
|
||
|
<a name="synassignment"></a>
|
||
|
<h3 id="synassignment"><a href="rbafzmst02.htm#ToC_1412">Description</a></h3>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold"><span class="italic">label</span></dt>
|
||
|
<dd>Specifies the label for the <span class="italic">assignment-statement</span> statement. The label name cannot be the same as another label within
|
||
|
the same scope. For more information, see <a href="rbafzmstsqlprocstmt.htm#psscope">Labels</a>.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="italic">SQL-parameter-name</span></dt>
|
||
|
<dd>Identifies the SQL parameter that is the assignment target. The SQL
|
||
|
parameter must be specified in <span class="italic">parameter-declaration</span> in
|
||
|
the CREATE PROCEDURE or CREATE FUNCTION statement.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="italic">SQL-variable-name</span></dt>
|
||
|
<dd>Identifies the SQL variable that is the assignment target. SQL variables
|
||
|
can be defined in a compound statement or be a transition variable.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="italic">expression</span> <span class="base">or</span> NULL</dt>
|
||
|
<dd>Specifies the expression or value that is the source for the assignment.
|
||
|
</dd>
|
||
|
<dt class="bold">DEFAULT</dt>
|
||
|
<dd>Specifies that the default value for the column associated with the
|
||
|
transition variable will be used. This can only be specified in SQL triggers
|
||
|
for transition variables.
|
||
|
</dd>
|
||
|
<dt class="bold"><span class="italic">row-fullselect</span></dt>
|
||
|
<dd>A fullselect that returns a single result row. The result column values
|
||
|
are assigned to the corresponding SQL variable or parameter. 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="wq1851"></a>
|
||
|
<h3 id="wq1851"><a href="rbafzmst02.htm#ToC_1413">Notes</a></h3>
|
||
|
<p><span class="bold">Assignment rules:</span> Assignments in the assignment statement
|
||
|
must conform to the SQL assignment rules as described in <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.
|
||
|
If assigning to a string variable, storage assignment rules apply.</p>
|
||
|
<p><span class="bold">Assignment rules for SQL parameters:</span> An IN parameter
|
||
|
can appear on the left or right side of an assignment-statement. When control
|
||
|
returns to the caller, the original value of the IN parameter is retained.
|
||
|
An OUT parameter can also appear on the left or right side of an assignment-statement.
|
||
|
If used without first being assigned a value, the value is undefined. When
|
||
|
control returns to the caller, the last value that is assigned to an OUT parameter
|
||
|
is returned to the caller. For an INOUT parameter, the first value of the
|
||
|
parameter is determined by the caller, and the last value that is assigned
|
||
|
to the parameter is returned to the caller.</p>
|
||
|
<p><span class="bold">Special Registers:</span> If a variable has been declared
|
||
|
with an identifier that matches the name of a special register (such as PATH),
|
||
|
then the variable must be delimited to distinguish it from assignment to the
|
||
|
special register (for example, SET "PATH" = 1; for a variable called PATH
|
||
|
declared as an integer).</p>
|
||
|
<p><span class="bold">SQLCODE and SQLSTATE:</span> The SQLCODE and SQLSTATE will
|
||
|
be reset and the diagnostic area or SQLCA initialized for each <span class="italic">assignment-statement</span> other than <span class="italic">assignment-statements</span> that:</p>
|
||
|
<ul>
|
||
|
<li>assign the SQLSTATE or SQLCODE variable to another variable or</li>
|
||
|
<li>set a constant value into the SQLSTATE or SQLCODE variable.</li></ul>
|
||
|
<a name="wq1852"></a>
|
||
|
<h3 id="wq1852"><a href="rbafzmst02.htm#ToC_1414">Example</a></h3>
|
||
|
<p>Increase the SQL variable p_salary by 10 percent.</p>
|
||
|
<pre class="xmp"> <span class="bold">SET</span> p_salary = p_salary + (p_salary * .10)
|
||
|
</pre>
|
||
|
<p>Set SQL variable p_salary to the null value</p>
|
||
|
<pre class="xmp"> <span class="bold">SET</span> p_salary = <span class="bold">NULL</span></pre>
|
||
|
<hr /><br />
|
||
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstsqlprocstmt.htm">Previous Page</a> | <a href="rbafzmstcallstmt.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>
|