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

87 lines
6.5 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="Return result sets from stored procedures" />
<meta name="abstract" content="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." />
<meta name="description" content="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." />
<meta name="DC.subject" content="stored procedures, returning result sets, CREATE PROCEDURE statement, statements, CREATE PROCEDURE, invoking" />
<meta name="keywords" content="stored procedures, returning result sets, CREATE PROCEDURE statement, statements, CREATE PROCEDURE, invoking" />
<meta name="DC.Relation" scheme="URI" content="rbafysproeg.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafyresultsete1.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafyresultsete2.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="rbafyresultsets" />
<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>Return result sets from stored procedures</title>
</head>
<body id="rbafyresultsets"><a name="rbafyresultsets"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Return result sets from stored procedures</h1>
<div><p>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.</p>
<div class="section"><p>Whether a result set gets returned depends on the returnability
attribute of the cursor. The cursor's returnability attribute can be explicitly
given in the DECLARE CURSOR statement or it can be defaulted. The SET RESULT
SETS statement also allows for an indication of where the result sets should
be returned. By default, cursors which are opened in a stored procedure are
defined to have a returnability attribute of RETURN TO CALLER. To return the
result set associated with the cursor to the application which called the
outermost procedure in the call stack, the returnability attribute of RETURN
TO CLIENT is specified on the DECLARE CURSOR statement. This will allow inner
procedures to return result sets when the application calls nested procedures.
For cursors whose result sets are never to be returned to caller or client,
the returnability attribute of WITHOUT RETURN is specified on the DECLARE
CURSOR statement.</p>
</div>
<div class="section"><p>There are many cases where opening the cursor in a stored procedure
and returning its result set provides advantages over opening the cursor directly
in the application. For instance, security to the tables referenced in the
query can be adopted from the stored procedure so that users of the application
do not need to be granted direct authority to the tables. Instead, they are
given authority to call the stored procedure, which is compiled with adequate
authority to access the tables. Another advantage to opening the cursors in
the stored procedure is that multiple result sets can be returned from a single
call to the stored procedure, which can be more efficient that opening the
cursors separately from the calling application. Additionally, each call to
the same stored procedure may return a different number of result sets, providing
some application versatility.</p>
</div>
<div class="section"><div class="p">The interfaces that can work with stored procedure result sets
include JDBC, CLI, and ODBC. An example on how to use these API interfaces
for working with stored procedure result sets is included in the following
examples. <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>
</div>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rbafyresultsete1.htm">Example 1: Call a stored procedure which returns a single result set</a></strong><br />
This example shows the API calls ODBC application would make when calling a stored procedure that returns a result set.</li>
<li class="ulchildlink"><strong><a href="rbafyresultsete2.htm">Example 2: Call a stored procedure which returns a result set from a nested procedure</a></strong><br />
This example shows how a nested stored procedure can open and return a result set to the outermost procedure.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafysproeg.htm" title="A procedure (often called a stored procedure) is a program that can be called to perform operations that can include both host language statements and SQL statements. Procedures in SQL provide the same benefits as procedures in a host language.">Stored procedures</a></div>
</div>
</div>
</body>
</html>