ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafyresultsete1.htm

97 lines
4.9 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 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 1: Call a stored procedure which returns a single result set" />
<meta name="abstract" content="This example shows the API calls ODBC application would make when calling a stored procedure that returns a result set." />
<meta name="description" content="This example shows the API calls ODBC application would make when calling a stored procedure that returns a result set." />
<meta name="DC.Relation" scheme="URI" content="rbafyresultsets.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="rbafyresultsete1" />
<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 1: Call a stored procedure which returns a single result set</title>
</head>
<body id="rbafyresultsete1"><a name="rbafyresultsete1"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example 1: Call a stored procedure which returns a single result set</h1>
<div><p>This example shows the API calls ODBC application would make when
calling a stored procedure that returns a result set. </p>
<div class="section"><p>Note that in this example the DECLARE CURSOR statement does not
have an explicit returnability specified. When there is only a single stored
procedure on the call stack, the returnability attribute of RETURN TO CALLER
as well as that of RETURN TO CLIENT will make the result set available to
the caller of the application. Also note that the stored procedure is defined
with a DYNAMIC RESULT SETS clause. For SQL procedures, this clause is required
if the stored procedure will be returning result sets.</p>
</div>
<div class="section"><p>Defining the stored procedure: </p>
<pre>PROCEDURE prod.resset
CREATE PROCEDURE prod.resset () LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C1 CURSOR FOR SELECT * FROM QIWS.QCUSTCDT;
OPEN C1;
RETURN;
END </pre>
</div>
<div class="section"><h4 class="sectiontitle">ODBC application</h4><div class="note"><span class="notetitle">Note:</span> Some of the logic
has been removed.</div>
<div class="note"><span class="notetitle">Note:</span> By using the code examples, you agree to the
terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre> :
strcpy(stmt,"call prod.resset()");
rc = SQLExecDirect(hstmt,stmt,SQL_NTS);
if (rc == SQL_SUCCESS)
{
// CALL statement has executed successfully. Process the result set.
// Get number of result columns for the result set.
rc = SQLNumResultCols(hstmt, &amp;wNum);
if (rc == SQL_SUCCESS)
// Get description of result columns in result set
{ rc = SQLDescribeCol(hstmt,à);
if (rc == SQL_SUCCESS)
:
{
// Bind result columns based on attributes returned
//
rc = SQLBindCol(hstmt,à);
:
// FETCH records until EOF is returned
rc = SQLFetch(hstmt);
while (rc == SQL_SUCCESS)
{ // process result returned on the SQLFetch
:
rc = SQLFetch(hstmt);
}
:
}
// Close the result set cursor when done with it.
rc = SQLFreeStmt(hstmt,SQL_CLOSE);
:
</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyresultsets.htm" title="In addition to returning output parameters, stored procedures have a feature by which a result table associated with a cursor opened in the stored procedure (called a result set) can be returned to the application issuing the CALL statement. That application can then issue fetch requests to read the rows of the result set cursor.">Return result sets from stored procedures</a></div>
</div>
</div>
</body>
</html>