ibm-information-center/dist/eclipse/plugins/i5OS.ic.db2_5.4.0.1/rbafzmstresignalstmt.htm

257 lines
15 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="RESIGNAL statement, SQL-control-statement,
SQL statements, CLASS_ORIGIN, SUBCLASS_ORIGIN" />
<title>RESIGNAL 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="resignalstmt"></a>
<h2 id="resignalstmt"><a href="rbafzmst02.htm#ToC_1466">RESIGNAL statement</a></h2><a id="idx3364" name="idx3364"></a><a id="idx3365" name="idx3365"></a>
<p>The RESIGNAL statement is used within a handler to return an error or warning
condition.</p>
<a name="wq1895"></a>
<h3 id="wq1895"><a href="rbafzmst02.htm#ToC_1467">Syntax</a></h3>
<a href="rbafzmstresignalstmt.htm#syncresignal"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn422.htm"
border="0" /></span><a href="#skipsyn-421"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a>>>-+--------+-RESIGNAL------------------------------------------>
'-<span class="italic">label:</span>-'
>--+-------------------------------------------------------------------------------+->&lt;
| .-VALUE-. |
'-+-SQLSTATE--+-------+--+-<span><span class="italic">sqlstate-string-constant</span></span>-+-+--+--------------------+-'
| '-<span><span class="italic">sqlstate-string-variable</span></span>-' | '-<span class="italic">signal-information</span>-'
'-<span class="italic">condition-name</span>------------------------------------'
signal-information:
|--SET--+-MESSAGE_TEXT-------+--&nbsp;=&nbsp;--+-<span class="italic">SQL-variable-name</span>----------+--|
+-CONSTRAINT_CATALOG-+ +-<span class="italic">SQL-parameter-name</span>---------+
+-CONSTRAINT_SCHEMA--+ '-<span class="italic">diagnostic-string-constant</span>-'
+-CONSTRAINT_NAME----+
+-CATALOG_NAME-------+
+-SCHEMA_NAME--------+
+-TABLE_NAME---------+
+-COLUMN_NAME--------+
+-CURSOR_NAME--------+
+-CLASS_ORIGIN-------+
'-SUBCLASS_ORIGIN----'
</pre>
<a name="skipsyn-421" id="skipsyn-421"></a>
<a name="syncresignal"></a>
<h3 id="syncresignal"><a href="rbafzmst02.htm#ToC_1468">Description</a></h3>
<dl class="parml">
<dt class="bold"><span class="italic">label</span></dt>
<dd>Specifies the label for the RESIGNAL 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">SQLSTATE VALUE</dt>
<dd>Specifies the SQLSTATE that will be signalled. The specified
value must follow the rules for SQLSTATEs:
<ul>
<li>Each character must be from the set of digits ('0' through '9') or non-accented
upper case letters ('A' through 'Z').</li>
<li>The SQLSTATE class (first two characters) cannot be '00' since this represents
successful completion.</li></ul>
<p>If the SQLSTATE does not conform to these rules, an error is returned.</p>
<dl class="parml">
<dt class="bold"><span class="italic">sqlstate-string-constant</span></dt>
<dd>The <span class="italic">sqlstate-string-constant</span> must be a character
string constant with exactly 5 characters.
</dd>
<dt class="bold"><span class="italic">sqlstate-string-variable</span></dt>
<dd>The <span class="italic">sqlstate-string-variable</span> must
be a character, UTF-16 graphic, or UCS-2 graphic variable. The actual length
of the contents of the <span class="italic">sqlstate-string-variable</span> must
be 5.
</dd>
</dl>
</dd>
<dt class="bold"><span class="italic">condition-name</span></dt>
<dd>Specifies the name of the condition that will be returned. The <span class="italic">condition-name</span> must be declared within the compound statement.
</dd>
<dt class="bold">SET</dt>
<dd>Introduces the assignment of values to <span class="italic">condition-information-items</span>. The <span class="italic">condition-information-item</span> values can be
accessed using the GET DIAGNOSTICS statement. The only <span class="italic">condition-information-item</span> that can be accessed in the SQLCA is MESSAGE_TEXT.
<dl class="parml">
<dt class="bold">MESSAGE_TEXT</dt>
<dd>Specifies a string that describes the error or warning.
<p>If an SQLCA
is used, </p>
<ul>
<li>the string is returned in the SQLERRMC field of the SQLCA</li>
<li>if the actual length of the string is longer than 70 bytes, it is truncated
without a warning.</li></ul>
</dd>
<dt class="bold">CONSTRAINT_CATALOG</dt>
<dd>Specifies a string that indicates the name of the database that contains
a constraint related to the signalled error or warning.
</dd>
<dt class="bold">CONSTRAINT_SCHEMA</dt>
<dd>Specifies a string that indicates the name of the schema that contains
a constraint related to the signalled error or warning.
</dd>
<dt class="bold">CONSTRAINT_NAME</dt>
<dd>Specifies a string that indicates the name of a constraint related to
the signalled error or warning.
</dd>
<dt class="bold">CATALOG_NAME</dt>
<dd>Specifies a string that indicates the name of the database that contains
a table or view related to the signalled error or warning.
</dd>
<dt class="bold">SCHEMA_NAME</dt>
<dd>Specifies a string that indicates the name of the schema that contains
a table or view related to the signalled error or warning.
</dd>
<dt class="bold">TABLE_NAME</dt>
<dd>Specifies a string that indicates the name of a table or view related
to the signalled error or warning.
</dd>
<dt class="bold">COLUMN_NAME</dt>
<dd>Specifies a string that indicates the name of a column in the table
or view related to the signalled error or warning.
</dd>
<dt class="bold">CURSOR_NAME</dt>
<dd>Specifies a string that indicates the name of a cursor related to the
signalled error or warning.
</dd>
<dt class="bold">CLASS_ORIGIN</dt><a id="idx3366" name="idx3366"></a>
<dd>Specifies a string that indicates the origin of the SQLSTATE class related
to the signalled error or warning.
</dd>
<dt class="bold">SUBCLASS_ORIGIN</dt><a id="idx3367" name="idx3367"></a>
<dd>Specifies a string that indicates the origin of the SQLSTATE subclass
related to the signalled error or warning.
</dd>
<dt class="bold"><span class="italic">SQL-variable-name</span></dt>
<dd>Identifies an SQL variable declared within the <span class="italic">compound-statement</span>, that contains the value to be assigned to the <span class="italic">condition-information-item</span>. The SQL variable must be defined as CHAR, VARCHAR, UTF-16 or UCS-2
GRAPHIC, or UTF-16 or UCS-2 VARGRAPHIC variable.
</dd>
<dt class="bold"><span class="italic">SQL-parameter-name</span></dt>
<dd>Identifies an SQL parameter declared within the <span class="italic">compound-statement</span>, that contains the value to be assigned to the <span class="italic">condition-information-item</span>. The SQL parameter must be
defined as CHAR, VARCHAR, UTF-16 or UCS-2 GRAPHIC, or UTF-16 or UCS-2 VARGRAPHIC
variable.
</dd>
<dt class="bold"><span class="italic">diagnostic-string-constant</span></dt>
<dd>Specifies a character string constant that contains the value to be
assigned to the <span class="italic">condition-information-item</span>.
</dd>
</dl>
</dd>
</dl>
<a name="wq1896"></a>
<h3 id="wq1896"><a href="rbafzmst02.htm#ToC_1469">Notes</a></h3>
<p><span class="bold">SQLSTATE values:</span> Any valid SQLSTATE value can be
used in the RESIGNAL statement. However, it is recommended that programmers
define new SQLSTATEs based on ranges reserved for applications. This prevents
the unintentional use of an SQLSTATE value that might be defined by the database
manager in a future release.</p>
<p>SQLSTATE values are comprised of a two-character class code value, followed
by a three-character subclass code value. Class code values represent classes
of successful and unsuccessful execution conditions.</p>
<ul>
<li>SQLSTATE classes that begin with the characters '7' through '9' or 'I'
through 'Z' may be defined. Within these classes, any subclass may be defined.</li>
<li>SQLSTATE classes that begin with the characters '0' through '6' or 'A'
through 'H' are reserved for the database manager. Within these classes,
subclasses that begin with the characters '0' through 'H' are reserved for
the database manager. Subclasses that begin with the characters 'I' through
'Z' may be defined.</li></ul>
<p>For more information about SQLSTATEs, see the<a href="../rzala/rzalakickoff.htm"> SQL Messages
and Codes</a> book in the iSeries Information Center.</p>
<p><span class="bold">Assignment:</span> When the RESIGNAL statement is executed,
the value of each of the specified <span class="italic">string-constants</span> and <span class="italic">variables</span> is assigned (using storage assignment
rules) to the corresponding <span class="italic">condition-information-item</span>. For details on the assignment rules, see <a href="rbafzmstch2bas.htm#ch2bas">Assignments and comparisons</a>. For
details on the maximum length of specific <span class="italic">condition-information-items</span>, see <a href="rbafzmstgetdiag.htm#getdiag">GET DIAGNOSTICS</a>.</p>
<p><span class="bold">Processing a RESIGNAL statement:</span></p>
<ul>
<li>If the RESIGNAL statement is specified without a SQLSTATE clause
or a <span class="italic">condition-name</span>, the SQL function, SQL procedure,
or SQL trigger resignals the identical condition that invoked the handler
and the SQLCODE is not changed.</li>
<li>When a RESIGNAL statement is issued and an SQLSTATE or <span class="italic">condition-name</span> is specified, the SQLCODE is based on the SQLSTATE value
as follows:
<ul>
<li>If the specified SQLSTATE class is either '01' or '02', a warning or not
found is signalled and the SQLCODE is set to +438.</li>
<li>Otherwise, an exception is returned and the SQLCODE is set to &ndash;438.</li></ul></li></ul>
<p></p>
<p>If the SQLSTATE or condition indicates that an exception is signalled (SQLSTATE
class other than '01' or '02'):, </p>
<ul>
<li>If a handler exists in the same compound statement as the RESIGNAL statement,
and the <span class="italic">compound-statement</span> contains a handler for
SQLEXCEPTION or the specified SQLSTATE or condition; the exception is handled
and control is transferred to that handler.</li>
<li>If the <span class="italic">compound-statement</span> is nested and an outer
level <span class="italic">compound-statement</span> has a handler for SQLEXCEPTION
or the specified SQLSTATE or condition; the exception is handled and control
is transferred to that handler.</li>
<li>Otherwise, the exception is not handled and control is immediately returned
to the end of the compound statement.</li></ul>
<p>If the SQLSTATE or condition indicates that a warning (SQLSTATE class '01')
or not found (SQLSTATE class '02') is signalled: </p>
<ul>
<li>If a handler exists in the same compound statement as the RESIGNAL statement,
and the <span class="italic">compound-statement</span> contains a handler for
SQLWARNING (if the SQLSTATE class is '01'), NOT FOUND (if the SQLSTATE class
is '02'), or the specified SQLSTATE or condition; the warning or not found
condition is handled and control is transferred to that handler.</li>
<li>If the <span class="italic">compound-statement</span> is nested and an outer
level compound statement contains a handler for SQLWARNING (if the SQLSTATE
class is '01'), NOT FOUND (if the SQLSTATE class is '02'), or the specified
SQLSTATE or condition; the warning or not found condition is handled and the
exception is handled and control is returned to that handler.</li>
<li>Otherwise, the warning is not handled and processing continues with the
next statement.</li></ul>
<a name="wq1897"></a>
<h3 id="wq1897"><a href="rbafzmst02.htm#ToC_1470">Example</a></h3>
<p>This example detects a division by zero error. The IF statement uses a
SIGNAL statement to invoke the overflow condition handler. The condition handler
uses a RESIGNAL statement to return a different SQLSTATE value to the client
application.</p>
<pre class="xmp"><span class="bold">CREATE PROCEDURE</span> divide <span class="bold">( IN</span> numerator <span class="bold">INTEGER,
IN</span> denominator <span class="bold">INTEGER,
OUT</span> divide_result <span class="bold">INTEGER )</span>
<span class="bold">LANGUAGE SQL</span>
<span class="bold">BEGIN</span>
<span class="bold">DECLARE</span> overflow <span class="bold">CONDITION FOR</span> '22003';
<span class="bold">DECLARE CONTINUE HANDLER FOR</span> overflow
<span class="bold">RESIGNAL SQLSTATE</span> '22375';
<span class="bold">IF</span> denominator = 0 <span class="bold">THEN</span>
<span class="bold">SIGNAL</span> overflow;
<span class="bold">ELSE</span>
<span class="bold">SET</span> divide_result = numerator / denominator;
<span class="bold">END IF;</span>
<span class="bold">END</span>
</pre>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstrepeatstmt.htm">Previous Page</a> | <a href="rbafzmstreturnstmt.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>