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

87 lines
5.2 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="description, SQLSTATE, SQLCODE" />
<title>SQL return codes</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="cksql"></a>
<h2 id="cksql"><a href="rbafzmst02.htm#ToC_730">SQL return codes</a></h2>
<p>The GET DIAGNOSTICS statement can be used in all languages to return return
codes and other information about the previous SQL statement. For more information,
see <a href="rbafzmstgetdiag.htm#getdiag">GET DIAGNOSTICS</a>.</p>
<p>Additionally, each host language provides a mechanism for handling SQL
return codes:</p>
<ul>
<li>In C, COBOL, FORTRAN, and PL/I, an application program containing executable
SQL statements must provide at least one of the following:
<ul>
<li>A structure named SQLCA.</li>
<li>A stand-alone CHAR(5) (CHAR(6) in C) variable named SQLSTATE (SQLSTA
or SQLSTATE in FORTRAN).</li>
<li>A stand-alone integer variable named SQLCODE (SQLCOD in FORTRAN).</li></ul>A stand-alone SQLSTATE or SQLCODE must not be declared in a host structure.
Both a stand-alone SQLSTATE and SQLCODE may be provided.
<p>An SQLCA can be
obtained by using the INCLUDE SQLCA statement. If an SQLCA is provided, neither
a stand-alone SQLSTATE or SQLCODE can be provided. The SQLCA includes a character-string
variable named SQLSTATE (SQLSTT in FORTRAN) and an integer variable named
SQLCODE (SQLCOD in FORTRAN) .</p>
<p>A stand-alone SQLSTATE should be used
to conform with the SQL 1999 Core standard.</p></li>
<li>In Java&trade;, for error conditions, the getSQLState method can be used to get
the SQLSTATE and the getErrorCode method can be used to get the SQLCODE.</li>
<li>In REXX and RPG, an SQLCA is provided automatically.</li></ul>
<a name="wq1028"></a>
<h3 id="wq1028"><a href="rbafzmst02.htm#ToC_731">SQLSTATE</a></h3><a id="idx1271" name="idx1271"></a>
<p>Regardless of whether the application program provides an SQLCA or a stand-alone
variable, SQLSTATE is also set by the database manager after execution of
each SQL statement. Thus, application programs can check the execution of
SQL statements by testing SQLSTATE instead of SQLCODE.</p>
<p>SQLSTATE provides application programs with common codes for common error
conditions. Furthermore, SQLSTATE is designed so that application programs
can test for specific errors or classes of errors. The scheme is the same
for all database managers and is based on the ISO/ANSI SQL 2003 Core standard. A complete
list of SQLSTATE classes and SQLSTATEs associated with each SQLCODE is supplied
in the <a href="../rzala/rzalakickoff.htm">SQL Messages and Codes</a> book in the iSeries Information Center.</p>
<a name="wq1029"></a>
<h3 id="wq1029"><a href="rbafzmst02.htm#ToC_732">SQLCODE</a></h3><a id="idx1272" name="idx1272"></a>
<p>The SQLCODE is also set by the database manager after each SQL statement
is executed as follows: </p>
<ul>
<li>If SQLCODE = 0 and SQLWARN0 is blank, execution was successful.</li>
<li>If SQLCODE = 100, no data was found. For example, a FETCH statement returned
no data, because the cursor was positioned after the last row of the result
table.</li>
<li>If SQLCODE > 0 and not = 100, execution was successful with a warning.</li>
<li>If SQLCODE = 0 and SQLWARN0 = 'W', execution was successful with a warning.</li>
<li>If SQLCODE &lt; 0, execution was not successful.</li></ul>
<p>A complete listing of DB2 UDB for iSeries SQLCODEs and their corresponding SQLSTATEs
is provided in the <a href="../rzala/rzalakickoff.htm">SQL Messages and Codes</a> book in
the iSeries Information Center.</p>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmsthowsql.htm">Previous Page</a> | <a href="rbafzmstsqcomm.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>