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

443 lines
25 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="GET DIAGNOSTICS statement, SQL-control-statement,
SQL statements, in GET DIAGNOSTICS, CURRENT, STACKED,
SQL (Structured Query Language), description, GET DIAGNOSTICS" />
<title>GET DIAGNOSTICS 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="getdiag2"></a>
<h2 id="getdiag2"><a href="rbafzmst02.htm#ToC_1435">GET DIAGNOSTICS statement</a></h2>
<p><a id="idx3344" name="idx3344"></a><a id="idx3345" name="idx3345"></a></p>
<p></p>
<a name="getdiagp2"></a>
<p id="getdiagp2">The GET DIAGNOSTICS statement obtains information about
the previous SQL statement that was executed. The syntax of GET DIAGNOSTICS
in an SQL function, SQL procedure, or SQL trigger is a subset of what is supported
as a GET DIAGNOSTICS statement in other contexts. See <a href="rbafzmstgetdiag.htm#getdiag">GET DIAGNOSTICS</a> for
details.</p>
<a name="wq1873"></a>
<h3 id="wq1873"><a href="rbafzmst02.htm#ToC_1436">Syntax</a></h3>
<a href="rbafzmstgetdiag2.htm#syncdiagnostics2"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
<a name="wq1874"></a>
<div class="fignone" id="wq1874">
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn413.htm"
border="0" /></span><a href="#skipsyn-412"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a> .-CURRENT-.
>>-+--------+--GET--+---------+--DIAGNOSTICS--+-<span class="italic">statement-information</span>-+->&lt;
'-<span class="italic">label:</span>-' '-STACKED-' +-<span class="italic">condition-information</span>-+
'-<span class="italic">combined-information</span>--'
statement-information:
.-,---------------------------------------------------------.
V |
|----+-<span class="italic">SQL-variable-name-1</span>--+--&nbsp;=&nbsp;--<span class="italic">statement-information-item</span>-+--|
'-<span class="italic">SQL-parameter-name-1</span>-'
condition-information:
|--CONDITION--+-+-<span class="italic">SQL-variable-name-2</span>--+-+---------------------->
| '-<span class="italic">SQL-parameter-name-2</span>-' |
'-<span class="italic">integer</span>------------------'
.-,--------------------------------------------------------------.
V |
>----+-<span class="italic">SQL-variable-name-3</span>--+--&nbsp;=&nbsp;--+-<span class="italic">connection-information-item</span>-+-+--|
'-<span class="italic">SQL-parameter-name-3</span>-' '-<span class="italic">condition-information-item</span>--'
combined-information:
|--+-<span class="italic">SQL-variable-name-4</span>--+--&nbsp;=&nbsp;-------------------------------->
'-<span class="italic">SQL-parameter-name-4</span>-'
(1)
>--ALL--+------------------------------------------------------+-------|
| .-,------------------------------------------------. |
| V | |
'---+-STATEMENT------------------------------------+-+-'
'-+-CONDITION--+--+--------------------------+-'
'-CONNECTION-' +-+-<span class="italic">SQL-variable-name-5</span>--+-+
| '-<span class="italic">SQL-parameter-name-5</span>-' |
'-<span class="italic">integer</span>------------------'
</pre>
<a name="skipsyn-412" id="skipsyn-412"></a>
<a name="wq1875"></a>
<div class="notelisttitle" id="wq1875">Notes:</div>
<ol type="1">
<li>STATEMENT can only be specified once. If <span class="italic">SQL-variable-name-5</span>, <span class="italic">SQL-parameter-name-5</span>, or <span class="italic">integer</span> is not specified, CONDITION and CONNECTION can only be specified
once.</li>
</ol></div>
<a name="wq1877"></a>
<div class="fignone" id="wq1877">
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn414.htm"
border="0" /></span><a href="#skipsyn-413"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a>statement-information-item:
|--+-COMMAND_FUNCTION_CODE-----------+--------------------------|
+-DB2_DIAGNOSTIC_CONVERSION_ERROR-+
+-DB2_LAST_ROW--------------------+
+-DB2_NUMBER_CONNECTIONS----------+
+-DB2_NUMBER_PARAMETER_MARKERS----+
+-DB2_NUMBER_RESULT_SETS----------+
+-DB2_NUMBER_ROWS-----------------+
+-DB2_NUMBER_SUCCESSFUL_SUBSTMTS--+
+-DB2_RELATIVE_COST_ESTIMATE------+
+-DB2_RETURN_STATUS---------------+
+-DB2_ROW_COUNT_SECONDARY---------+
+-DB2_ROW_LENGTH------------------+
+-DB2_SQL_ATTR_CONCURRENCY--------+
+-DB2_SQL_ATTR_CURSOR_CAPABILITY--+
+-DB2_SQL_ATTR_CURSOR_HOLD--------+
+-DB2_SQL_ATTR_CURSOR_ROWSET------+
+-DB2_SQL_ATTR_CURSOR_SCROLLABLE--+
+-DB2_SQL_ATTR_CURSOR_SENSITIVITY-+
+-DB2_SQL_ATTR_CURSOR_TYPE--------+
+-DYNAMIC_FUNCTION----------------+
+-DYNAMIC_FUNCTION_CODE-----------+
+-MORE----------------------------+
+-NUMBER--------------------------+
+-ROW_COUNT-----------------------+
+-TRANSACTION_ACTIVE--------------+
+-TRANSACTIONS_COMMITTED----------+
'-TRANSACTIONS_ROLLED_BACK--------'
connection-information-item:
|--+-CONNECTION_NAME-----------+--------------------------------|
+-DB2_AUTHENTICATION_TYPE---+
+-DB2_AUTHID_TRUNCATION-----+
+-DB2_AUTHORIZATION_ID------+
+-DB2_CONNECTION_METHOD-----+
+-DB2_CONNECTION_NUMBER-----+
+-DB2_CONNECTION_STATE------+
+-DB2_CONNECTION_STATUS-----+
+-DB2_CONNECTION_TYPE-------+
+-DB2_DDM_SERVER_CLASS_NAME-+
+-DB2_DYN_QUERY_MGMT--------+
+-DB2_ENCRYPTION_TYPE-------+
+-DB2_EXPANSION_FACTOR_FROM-+
+-DB2_EXPANSION_FACTOR_TO---+
+-DB2_PRODUCT_ID------------+
+-DB2_SERVER_CLASS_NAME-----+
+-DB2_SERVER_NAME-----------+
'-DB2_USER_ID---------------'
</pre>
<a name="skipsyn-413" id="skipsyn-413"></a></div>
<a name="wq1878"></a>
<div class="fignone" id="wq1878">
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn415.htm"
border="0" /></span><a href="#skipsyn-414"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a>condition-information-item:
|--+-CATALOG_NAME------------------+----------------------------|
+-CLASS_ORIGIN------------------+
+-COLUMN_NAME-------------------+
+-CONDITION_IDENTIFIER----------+
+-CONDITION_NUMBER--------------+
+-CONSTRAINT_CATALOG------------+
+-CONSTRAINT_NAME---------------+
+-CONSTRAINT_SCHEMA-------------+
+-CURSOR_NAME-------------------+
+-DB2_ERROR_CODE1---------------+
+-DB2_ERROR_CODE2---------------+
+-DB2_ERROR_CODE3---------------+
+-DB2_ERROR_CODE4---------------+
+-DB2_INTERNAL_ERROR_POINTER----+
+-DB2_LINE_NUMBER---------------+
+-DB2_MESSAGE_ID----------------+
+-DB2_MESSAGE_ID1---------------+
+-DB2_MESSAGE_ID2---------------+
+-DB2_MESSAGE_KEY---------------+
+-DB2_MODULE_DETECTING_ERROR----+
+-DB2_NUMBER_FAILING_STATEMENTS-+
+-DB2_OFFSET--------------------+
+-DB2_ORDINAL_TOKEN_n-----------+
+-DB2_PARTITION_NUMBER----------+
+-DB2_REASON_CODE---------------+
+-DB2_RETURNED_SQLCODE----------+
+-DB2_ROW_NUMBER----------------+
+-DB2_SQLERRD_SET---------------+
+-DB2_SQLERRD1------------------+
+-DB2_SQLERRD2------------------+
+-DB2_SQLERRD3------------------+
+-DB2_SQLERRD4------------------+
+-DB2_SQLERRD5------------------+
+-DB2_SQLERRD6------------------+
+-DB2_TOKEN_COUNT---------------+
+-DB2_TOKEN_STRING--------------+
+-MESSAGE_LENGTH----------------+
+-MESSAGE_OCTET_LENGTH----------+
+-MESSAGE_TEXT------------------+
+-PARAMETER_MODE----------------+
+-PARAMETER_NAME----------------+
+-PARAMETER_ORDINAL_POSITION----+
+-RETURNED_SQLSTATE-------------+
+-ROUTINE_CATALOG---------------+
+-ROUTINE_NAME------------------+
+-ROUTINE_SCHEMA----------------+
+-SCHEMA_NAME-------------------+
+-SERVER_NAME-------------------+
+-SPECIFIC_NAME-----------------+
+-SUBCLASS_ORIGIN---------------+
+-TABLE_NAME--------------------+
+-TRIGGER_CATALOG---------------+
+-TRIGGER_NAME------------------+
'-TRIGGER_SCHEMA----------------'
</pre>
<a name="skipsyn-414" id="skipsyn-414"></a></div>
<a name="syncdiagnostics2"></a>
<h3 id="syncdiagnostics2"><a href="rbafzmst02.htm#ToC_1437">Description</a></h3>
<dl class="parml">
<dt class="bold">CURRENT <span class="base">or</span> STACKED</dt>
<dd>Specifies which diagnostics area to access.
<dl class="parml"><a id="idx3346" name="idx3346"></a>
<dt class="bold">CURRENT</dt>
<dd>Specifies to access the first diagnostics area. It corresponds to the
previous SQL statement that was executed and that was not a GET DIAGNOSTICS
statement. This is the default.
</dd><a id="idx3347" name="idx3347"></a>
<dt class="bold">STACKED</dt>
<dd>Specifies to access the second diagnostics area. The second diagnostics
area is only available within a handler. It corresponds to the previous SQL
statement that was executed before the handler was entered and that was not
a GET DIAGNOSTICS statement. If the GET DIAGNOSTICS statement is the first
statement within a handler, then the first diagnostics area and the second
diagnostics area contain the same diagnostics information.
</dd>
</dl>
</dd>
<dt class="bold"><var class="pv">statement-information</var></dt>
<dd>Returns information about the last SQL statement executed.
<dl class="parml">
<dt class="bold"><var class="pv">SQL-variable-name-1</var> or <var class="pv">SQL-parameter-name-1</var></dt>
<dd>Identifies a variable described in the program in accordance with the
rules for declaring SQL variables and SQL parameters. The data type of the
SQL variable or SQL parameter must be compatible with the data type as specified
in <a href="rbafzmstgetdiag.htm#getditable">Table 58</a> for the specified condition information item.
The SQL variable or SQL parameter is assigned the value of the specified statement
information item. If the value is truncated when assigning it to the SQL variable
or SQL parameter, a warning is returned (SQLSTATE 01004) and the GET_DIAGNOSTICS_DIAGNOSTICS
item of the diagnostics area is updated with the details of this condition.
<p>If a specified diagnostic item does not contain diagnostic information , then
the SQL variable or SQL parameter is set to a default value, based on its
data type: 0 for an exact numeric diagnostic item, an empty string for a VARCHAR
diagnostic item and blanks for a CHAR diagnostic item.</p>
</dd>
</dl>
</dd>
<dt class="bold"><var class="pv">condition-information</var></dt>
<dd>Returns information about the condition or conditions that occurred
when the last SQL statement was executed.
<dl class="parml">
<dt class="bold">CONDITION <var class="pv">SQL-variable-name-2</var> or <var class="pv">SQL-parameter-name-2</var> or <var class="pv">integer</var></dt>
<dd>Identifies the diagnostic for which information is requested. Each diagnostic
that occurs while executing an SQL statement is assigned an integer. The value
1 indicates the first diagnostic, 2 indicates the second diagnostic and so
on. If the value is 1, then the diagnostic information retrieved corresponds
to the condition indicated by the SQLSTATE value actually returned by the
execution of the previous SQL statement (other than a GET DIAGNOSTICS statement).
The SQL variable or SQL parameter specified must be described in the program
in accordance with the rules for declaring numeric SQL variables or SQL parameters.
The value specified must not be less than one or greater than the number of
available diagnostics
</dd>
<dt class="bold"><var class="pv">SQL-variable-name-3</var> or <var class="pv">SQL-parameter-name-3</var></dt>
<dd>Identifies a variable described in the program in accordance with the
rules for declaring SQL variables or SQL parameters. The data type of the
SQL variable or SQL parameter must be compatible with the data type as specified
in <a href="rbafzmstgetdiag.htm#getditable">Table 58</a> for the specified condition information item.
The SQL variable or SQL parameter is assigned the value of the specified statement
information item. If the value is truncated when assigning it to the SQL variable
or SQL parameter, a warning is returned (SQLSTATE 01004) and the GET_DIAGNOSTICS_DIAGNOSTICS
item of the diagnostics area is updated with the details of this condition.
<p>If a specified diagnostic item does not contain diagnostic information , then
the SQL variable or SQL parameter is set to a default value, based on its
data type: 0 for an exact numeric diagnostic item, an empty string for a VARCHAR
diagnostic item and blanks for a CHAR diagnostic item.</p>
</dd>
<dt class="bold"><var class="pv">combined-information</var></dt>
<dd>Returns multiple information items combined into one string.
<p>If the
GET DIAGNOSTICS statement is specified in an SQL function, SQL procedure,
or trigger, the GET DIAGNOSTICS statement must be the first statement specified
in the handler that will handle the error.</p>
<p>If information is desired
about a warning, </p>
<ul>
<li>If a handler will get control for the warning condition, the GET DIAGNOSTICS
statement must be the first statement specified in that handler.</li>
<li>If a handler will not get control for the warning condition, the GET DIAGNOSTICS
statement must be the next statement executed after that previous statement.</li></ul>
<dl class="parml">
<dt class="bold"><var class="pv">SQL-variable-name-4</var> or <var class="pv">SQL-parameter-name-4</var></dt>
<dd>Identifies a variable described in the program in accordance with the
rules for declaring SQL variables or SQL parameters. The data type of the
SQL variable or SQL parameter must be VARCHAR. If the length of <var class="pv">SQL-variable-name-4</var> or <var class="pv">SQL-parameter-name-4</var> is not sufficient to hold the full
returned diagnostic string, the string is truncated, a warning is returned
(SQLSTATE 01004) and the GET_DIAGNOSTICS_DIAGNOSTICS item of the diagnostics
area is updated with the details of this condition.
</dd>
<dt class="bold">ALL</dt>
<dd>Indicates that all diagnostic items that are set for the last SQL statement
executed should be combined into one string. The format of the string is a
semicolon separated list of all of the available diagnostic information in
the form:
<pre class="xmp"><var class="pv">item-name</var>=<var class="pv">character-form-of-the-item-value</var>;</pre>The character form of a positive numeric value will not contain a leading
plus sign (+) unless the item is RETURNED_SQLCODE. In this case, a leading
plus sign (+) is added. For example:
<pre class="xmp"> NUMBER=1;RETURNED_SQLSTATE=02000;DB2_RETURNED_SQLCODE=+100;</pre> Only items that contain diagnostic information are included in the
string.
</dd>
<dt class="bold">STATEMENT</dt>
<dd>Indicates that all <var class="pv">statment-information-item</var> diagnostic items
that contain diagnostic information for the last SQL statement executed should
be combined into one string. The format is the same as described above for
ALL.
</dd>
<dt class="bold">CONDITION</dt>
<dd>Indicates that <var class="pv">condition-information-item</var> diagnostic items
that contain diagnostic information for the last SQL statement executed should
be combined into one string. If <var class="pv">SQL-variable-name-5</var> or <var class="pv">SQL-parameter-name-5</var> or <var class="pv">integer</var> is specified, then the format is the same as described
above for the ALL option. If <var class="pv">SQL-variable-name-5</var> or <var class="pv">SQL-parameter-name-5</var> or <var class="pv">integer</var> is not specified, then the format includes a condition
number entry at the beginning of the information for that condition in the
form:
<pre class="xmp">CONDITION_NUMBER=X;<var class="pv">item-name</var>=<var class="pv">character-form-of-the-item-value</var>;</pre> where X is the number of the condition. For example:
<pre class="xmp">CONDITION_NUMBER=1;RETURNED_SQLSTATE=02000;RETURNED_SQLCODE=+100;
CONDITION_NUMBER=2;RETURNED_SQLSTATE=01004;</pre>
</dd>
<dt class="bold">CONNECTION</dt>
<dd>Indicates that <var class="pv">connection-information-item</var> diagnostic items
that contain diagnostic information for the last SQL statement executed should
be combined into one string. If <var class="pv">SQL-variable-name-5</var> or <var class="pv">SQL-parameter-name-5</var> or <var class="pv">integer</var> is specified, then the format is the same as described
above for ALL. If <var class="pv">SQL-variable-name-5</var> or <var class="pv">SQL-parameter-name-5</var> or <var class="pv">integer</var> is not specified, then the format includes a connection
number entry at the beginning of the information for that condition in the
form:
<pre class="xmp">CONNECTION_NUMBER=X;<var class="pv">item-name</var>=<var class="pv">character-form-of-the-item-value</var>;</pre>where X is the number of the condition. For example:
<pre class="xmp">CONNECTION_NUMBER=1;CONNECTION_NAME=SVL1;DB2_PRODUCT_ID=DSN07010;</pre>
</dd>
<dt class="bold"><var class="pv">SQL-variable-name-5</var> or <var class="pv">SQL-parameter-name-5</var> or <var class="pv">integer</var></dt>
<dd>Identifies the diagnostic for which ALL CONDITION or ALL CONNECTION
information is requested. The SQL variable or SQL parameter specified must
be described in the program in accordance with the rules for declaring numeric
SQL variables or SQL parameters. The value specified must not be less than
one or greater than the number of available diagnostics.
</dd>
</dl>
</dd>
</dl>
</dd>
<dt class="bold"><var class="pv">statement-information-item</var></dt>
<dd>For a description of the <var class="pv">statement-information-items</var>, see <a href="rbafzmstgetdiag.htm#getdsitem"><span><var class="pv">statement-information-item</var></span></a>.
</dd>
<dt class="bold"><var class="pv">connection-information-item</var></dt>
<dd>For a description of the <var class="pv">connection-information-items</var>, see <a href="rbafzmstgetdiag.htm#getdcoitem"><span><var class="pv">connection-information-item</var></span></a>.
</dd>
<dt class="bold"><var class="pv">condition-information-item</var></dt>
<dd>For a description of the <var class="pv">condition-information-items</var>, see <a href="rbafzmstgetdiag.htm#getdcitem"><span><var class="pv">condition-information-item</var></span></a>.
</dd>
</dl>
<a name="wq1879"></a>
<h3 id="wq1879"><a href="rbafzmst02.htm#ToC_1438">Notes</a></h3>
<p><span class="bold">Effect of statement</span>: The GET DIAGNOSTICS statement
does not change the contents of the diagnostics area (SQLCA). If an SQLSTATE
or SQLCODE special variable is declared in an SQL procedure, SQL function,
or SQL trigger, these are set to the SQLSTATE or SQLCODE returned from issuing
the GET DIAGNOSTICS statement.</p>
<p>If the SQLSTATE or SQLCODE values are needed by the handler following the
GET DIAGNOSTIC statement, then either they must be saved or they can be accessed
by specifying the DB2_RETURNED_SQLCODE or the RETURNED_SQLSTATE condition
items on the GET DIAGNOSTIC statement.</p>
<p><span class="bold">Case of return values</span>: Values for identifiers in
returned diagnostic items are not delimited and are case sensitive. For example,
a table name of "abc" would be returned, simply as abc.</p>
<p><span class="bold">Data types for items</span>: When a diagnostic item is assigned
to a SQL variable or SQL parameter, the SQL variable or SQL parameter must
be compatible with the data type of the diagnostic item. For more information,
see <a href="rbafzmstgetdiag.htm#getditable">Table 58</a>.</p>
<p><span class="bold">Keyword Synonym:</span> The following keywords are synonyms
supported for compatibility to prior releases. These keywords are non-standard
and should not be used:</p>
<ul>
<li>The keyword EXCEPTION can be used as a synonym for CONDITION.</li>
<li>The keyword RETURN_STATUS can be used as a synonym for DB2_RETURN_STATUS.</li></ul>
<a name="wq1880"></a>
<h3 id="wq1880"><a href="rbafzmst02.htm#ToC_1439">Example</a></h3>
<p>In an SQL procedure, execute a GET DIAGNOSTICS statement to determine how
many rows were updated.</p>
<pre class="xmp"> <span class="bold">CREATE PROCEDURE</span> sqlprocg <span class="bold">(IN</span> deptnbr <span class="bold">VARCHAR(</span>3<span class="bold">))</span>
<span class="bold">LANGUAGE SQL</span>
<span class="bold">BEGIN</span>
<span class="bold">DECLARE SQLSTATE CHAR(</span>5<span class="bold">)</span>;
<span class="bold">DECLARE</span> rcount <span class="bold">INTEGER</span>;
<span class="bold">UPDATE</span> CORPDATA.PROJECT
<span class="bold">SET</span> PRSTAFF <span class="bold">=</span> PRSTAFF <span class="bold">+</span> 1.5
<span class="bold">WHERE</span> DEPTNO <span class="bold">=</span> deptnbr;
<span class="bold">GET DIAGNOSTICS</span> rcount <span class="bold">= ROW_COUNT</span>;
/* At this point, rcount contains the number of rows that were updated. */
<span class="bold">END</span>
</pre>
<p>Within an SQL procedure, handle the returned status value from the invocation
of a stored procedure called TRYIT. TRYIT could use the RETURN statement to
explicitly return a status value or a status value could be implicitly returned
by the database manager. If the procedure is successful, it returns a value
of zero.</p>
<pre class="xmp"> <span class="bold">CREATE PROCEDURE</span> TESTIT <span class="bold">()</span>
<span class="bold">LANGUAGE SQL</span>
A1: <span class="bold">BEGIN</span>
<span class="bold">DECLARE</span> RETVAL <span class="bold">INTEGER DEFAULT</span> 0;
...
<span class="bold">CALL</span> TRYIT
<span class="bold">GET DIAGNOSTICS</span> RETVAL <span class="bold">= RETURN_STATUS</span>;
<span class="bold">IF</span> RETVAL <span class="bold">&lt;></span> 0 <span class="bold">THEN</span>
...
<span class="bold">LEAVE</span> A1;
<span class="bold">ELSE</span>
...
<span class="bold">END IF</span>;
<span class="bold">END</span> A1
</pre>
<p>In an SQL procedure, execute a GET DIAGNOSTICS statement to retrieve the
message text for an error.</p>
<pre class="xmp"> <span class="bold">CREATE PROCEDURE</span> divide2 <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,
OUT</span> divide_error <span class="bold">VARCHAR(70) )</span>
<span class="bold">LANGUAGE SQL</span>
<span class="bold">BEGIN</span>
<span class="bold">DECLARE CONTINUE HANDLER FOR SQLEXCEPTION</span>
<span class="bold">GET DIAGNOSTICS EXCEPTION 1</span>
divide_error <span class="bold">= MESSAGE_TEXT</span>;
<span class="bold">SET</span> divide_result = numerator / denominator;
<span class="bold">END</span>; </pre><a id="idx3348" name="idx3348"></a><a id="idx3349" name="idx3349"></a><a id="idx3350" name="idx3350"></a><a id="idx3351" name="idx3351"></a>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstforstmt.htm">Previous Page</a> | <a href="rbafzmstgotostmt.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>