144 lines
9.3 KiB
HTML
144 lines
9.3 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 variable statement, SET variable,
|
|
SQL statements, in statement, expression, in SET variable statement, NULL,
|
|
row-fullselect, *CNULRQD precompiler option, *NOCNULRQD precompiler option" />
|
|
<title>SET 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="setinto"></a>
|
|
<h2 id="setinto"><a href="rbafzmst02.htm#ToC_1362">SET variable</a></h2><a id="idx3232" name="idx3232"></a><a id="idx3233" name="idx3233"></a>
|
|
<p>The SET variable statement produces a result table consisting of at most
|
|
one row and assigns the values in that row to variables.</p>
|
|
<a name="wq1812"></a>
|
|
<h3 id="wq1812"><a href="rbafzmst02.htm#ToC_1363">Invocation</a></h3>
|
|
<p>This statement can only be embedded in an application program. It is an
|
|
executable statement that cannot be dynamically prepared. It must not be specified
|
|
in REXX.</p>
|
|
<a name="wq1813"></a>
|
|
<h3 id="wq1813"><a href="rbafzmst02.htm#ToC_1364">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="wq1814"></a>
|
|
<h3 id="wq1814"><a href="rbafzmst02.htm#ToC_1365">Syntax</a></h3>
|
|
<a href="rbafzmstsetinto.htm#synssv"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<p> </p>
|
|
<a name="wq1815"></a>
|
|
<div class="fignone" id="wq1815">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn395.htm"
|
|
border="0" /></span><a href="#skipsyn-394"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a> .-,---------------------------------------------------------.
|
|
V |
|
|
>>-SET----+-<span><span class="italic">variable</span></span>-- = --+-<span class="italic">expression</span>-+-------------------------+-+-><
|
|
| '-NULL-------' |
|
|
| .-,--------. .-,--------------. |
|
|
| V | V | |
|
|
'-(----<span><span class="italic">variable</span></span>-+--)-- = --(--+---+-<span class="italic">expression</span>-+-+-+--)-'
|
|
| '-NULL-------' |
|
|
'-<span><span class="italic">row-fullselect</span></span>-----'
|
|
|
|
</pre>
|
|
<a name="skipsyn-394" id="skipsyn-394"></a></div>
|
|
<a name="synssv"></a>
|
|
<h3 id="synssv"><a href="rbafzmst02.htm#ToC_1366">Description</a></h3>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">variable, ...</var></dt>
|
|
<dd>Identifies one or more variables or host structures that must be declared
|
|
in accordance with the rules for declaring variables (see <a href="rbafzmstch2refvar.htm#ch2host">References to host variables</a>).
|
|
A host structure is logically replaced by a list of variables that represent
|
|
each of the elements of the host structure.
|
|
<p>The value to be assigned to
|
|
each <var class="pv">variable</var> can be specified immediately following the <var class="pv">variable</var>, for example, <var class="pv">variable</var> = <var class="pv">expression</var>, <var class="pv">variable</var> = <var class="pv">expression</var>. Or, sets
|
|
of parentheses can be used to specify all the <var class="pv">variables</var> and
|
|
then all the values, for example, (<var class="pv">variable</var>, <var class="pv">variable</var>) = (<var class="pv">expression</var>, <var class="pv">expression</var>).</p>
|
|
<p>The data
|
|
type of each variable must be compatible with its corresponding result column.
|
|
Each assignment is made according to the rules described in <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>.
|
|
The number of <var class="pv">variables</var> specified to the left of the equal
|
|
operator must equal the number of values in the corresponding result specified
|
|
to the right of the equal operator. If the value is null, an indicator variable
|
|
must be provided. If an assignment error occurs, the value is not assigned
|
|
to the variable, and no more values are assigned to variables. Any values
|
|
that have already been assigned to variables remain assigned.</p>
|
|
<p>If an
|
|
error occurs as the result of an arithmetic expression in the <var class="pv">expression</var> or SELECT list of the subselect (division by zero, or overflow) or a
|
|
character conversion error occurs, the result is the null value. As in any
|
|
other case of a null value, an indicator variable must be provided. The value
|
|
of the variable is undefined. In this case, however, the indicator variable
|
|
is set to -2. Processing of the statement continues as if the error had not
|
|
occurred. (However, a warning is returned.) If you do not provide an indicator
|
|
variable, an error is returned. It is possible that some values have already
|
|
been assigned to variables and will remain assigned when the error occurs.</p>
|
|
</dd>
|
|
<dt class="bold"><var class="pv">expression</var> </dt><a id="idx3234" name="idx3234"></a>
|
|
<dd>Specifies the new value of the variable. The <var class="pv">expression</var> is
|
|
any expression of the type described in <a href="rbafzmstch2expr.htm#ch2expr">Expressions</a>.
|
|
It must not include a column name.
|
|
</dd>
|
|
<dt class="bold">NULL</dt><a id="idx3235" name="idx3235"></a>
|
|
<dd>Specifies that the new value for the variable is the null value.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">row-fullselect</var></dt><a id="idx3236" name="idx3236"></a>
|
|
<dd>A fullselect that returns a single result row. The result column values
|
|
are assigned to each corresponding <var class="pv">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="wq1816"></a>
|
|
<h3 id="wq1816"><a href="rbafzmst02.htm#ToC_1367">Notes</a></h3>
|
|
<p><span class="bold">Variable assignment:</span> If the specified variable is
|
|
character and is not large enough to contain the result, a warning (SQLSTATE
|
|
01004) is returned (and 'W' is assigned to SQLWARN1 in the SQLCA).
|
|
The actual length of the result is returned in the indicator variable associated
|
|
with the variable, if an indicator variable is provided.</p>
|
|
<p>If the specified variable is a C NUL-terminated variable and is not large
|
|
enough to contain the result and the NUL-terminator:</p>
|
|
<ul>
|
|
<li>If the *CNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command
|
|
(or CNULRQD(*YES) on the SET OPTION statement), the following occurs:<a id="idx3237" name="idx3237"></a>
|
|
<ul>
|
|
<li>The result is truncated.</li>
|
|
<li>The last character is the NUL-terminator.</li>
|
|
<li>The value 'W' is assigned to SQLWARN1 in the SQLCA.</li></ul></li>
|
|
<li>If the *NOCNULRQD option on the CRTSQLCI or CRTSQLCPPI command (or CNULRQD(*NO)
|
|
on the SET OPTION statement) is specified, the following occurs:<a id="idx3238" name="idx3238"></a>
|
|
<ul>
|
|
<li>The NUL-terminator is not returned.</li>
|
|
<li>The value 'N' is assigned to SQLWARN1 in the SQLCA.</li></ul></li></ul>
|
|
<a name="wq1817"></a>
|
|
<h3 id="wq1817"><a href="rbafzmst02.htm#ToC_1368">Examples</a></h3>
|
|
<p><span class="italic">Example 1:</span> Assign the value of the CURRENT PATH
|
|
special register to host variable HV1. </p>
|
|
<pre class="xmp"> EXEC SQL <span class="bold">SET</span> :HV1 <span class="bold">= CURRENT PATH</span>;</pre>
|
|
<p><span class="italic">Example 2:</span> Assume that LOB locator LOB1 is associated
|
|
with a CLOB value. Assign a portion of the CLOB value to host variable DETAILS
|
|
using the LOB locator. </p>
|
|
<pre class="xmp"> EXEC SQL <span class="bold">SET</span> :DETAILS <span class="bold">= SUBSTR(</span>:LOB1,1,35<span class="bold">)</span>;</pre>
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstsettranv.htm">Previous Page</a> | <a href="rbafzmstsignal.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>
|