71 lines
3.4 KiB
HTML
71 lines
3.4 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 lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<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="DC.Type" content="reference" />
|
|
<meta name="DC.Title" content="Example: SQL routine exception" />
|
|
<meta name="abstract" content="In this application example, a stored procedure signals an error when an input value is out of range." />
|
|
<meta name="description" content="In this application example, a stored procedure signals an error when an input value is out of range." />
|
|
<meta name="DC.Relation" scheme="URI" content="rzajpdiagnostics.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="rzajpdiagex" />
|
|
<meta name="DC.Language" 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. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Example: SQL routine exception</title>
|
|
</head>
|
|
<body id="rzajpdiagex"><a name="rzajpdiagex"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Example: SQL routine exception</h1>
|
|
<div><p>In this application example, a stored procedure signals an error
|
|
when an input value is out of range. </p>
|
|
<div class="section"><pre>EXEC SQL <strong>CREATE PROCEDURE</strong> check_input (<strong>IN</strong> p1 <strong>INT</strong>)
|
|
<strong>LANGUAGE SQL READS SQL DATA</strong>
|
|
test: <strong>BEGIN</strong>
|
|
<strong>IF</strong> p1< 0 <strong>THEN</strong>
|
|
<strong>SIGNAL SQLSTATE VALUE</strong> '99999'
|
|
SET <strong>MESSAGE_TEXT</strong> = 'Bad input value';
|
|
<strong>END IF</strong>
|
|
<strong>END</strong> test;</pre>
|
|
</div>
|
|
<div class="section"><p>The calling application checks for a failure and retrieves the
|
|
information about the failure from the SQL diagnostics area: </p>
|
|
<pre>char SQLSTATE[6]; /* Stand-alone sqlstate */
|
|
long int SQLCODE; /* Stand-alone sqlcode */
|
|
|
|
long int hv1;
|
|
char hv2[6];
|
|
char hv3[256];
|
|
|
|
hv1 = -1;
|
|
EXEC SQL CALL check_input(:hv1);
|
|
|
|
if (strncmp(SQLSTATE, "99999", 5) == 0)
|
|
{
|
|
EXEC SQL GET DIAGNOSTICS CONDITION 1
|
|
:hv2 = RETURNED_SQLSTATE,
|
|
:hv3 = MESSAGE_TEXT;
|
|
}
|
|
else
|
|
{
|
|
}</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajpdiagnostics.htm" title="The SQL diagnostics area is used to keep the returned information for an SQL statement that has been run in a program. It contains all the information that is available to you as an application programmer through the SQLCA.">Use the SQL diagnostics area</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |