120 lines
8.8 KiB
HTML
120 lines
8.8 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="concept" />
|
||
|
<meta name="DC.Title" content="Stored procedures" />
|
||
|
<meta name="abstract" content="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." />
|
||
|
<meta name="description" content="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." />
|
||
|
<meta name="DC.subject" content="CREATE PROCEDURE statement, statements, CREATE PROCEDURE, external procedure, SQL procedure, stored procedures" />
|
||
|
<meta name="keywords" content="CREATE PROCEDURE statement, statements, CREATE PROCEDURE, external procedure, SQL procedure, stored procedures" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyroutines.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydfnid.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafysqlproc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyinvokeproc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyresultsets.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyppcsp.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyindicator.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyreturningstatus.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafystored1.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydrdastoredproc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstcreatep.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../rzaha/jsqlrout.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="rbafysproeg" />
|
||
|
<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>Stored procedures</title>
|
||
|
</head>
|
||
|
<body id="rbafysproeg"><a name="rbafysproeg"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Stored procedures</h1>
|
||
|
<div><p>A <em>procedure</em> (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.</p>
|
||
|
<p>DB2<sup>®</sup> SQL
|
||
|
for <span class="keyword">iSeries™</span> stored procedure
|
||
|
support provides a way for an SQL application to define and then call a procedure
|
||
|
through SQL statements. Stored procedures can be used in both distributed
|
||
|
and non-distributed DB2 SQL for <span class="keyword">iSeries</span> applications.
|
||
|
One of the big advantages in using stored procedures is that for distributed
|
||
|
applications, the execution of one CALL statement on the application requester,
|
||
|
or client, can perform any amount of work on the application server. </p>
|
||
|
<p>You may define a procedure as either an SQL procedure or an external procedure.
|
||
|
An external procedure can be any supported high level language program (except
|
||
|
System/36* programs and procedures) or a REXX procedure. The procedure does
|
||
|
not need to contain SQL statements, but it may contain SQL statements. An
|
||
|
SQL procedure is defined entirely in SQL, and can contain SQL statements that
|
||
|
include SQL control statements.</p>
|
||
|
<p>Coding stored procedures requires that the user understand the following:
|
||
|
</p>
|
||
|
<ul><li>Stored procedure definition through the CREATE PROCEDURE statement</li>
|
||
|
<li>Stored procedure invocation through the CALL statement</li>
|
||
|
<li>Parameter passing conventions</li>
|
||
|
<li>Methods for returning a completion status to the program invoking the
|
||
|
procedure.</li>
|
||
|
</ul>
|
||
|
<p>You may define stored procedures by using the CREATE PROCEDURE statement.
|
||
|
The CREATE PROCEDURE statement adds procedure and parameter definitions to
|
||
|
the catalog tables SYSROUTINES and SYSPARMS. These definitions are then accessible
|
||
|
by any SQL CALL statement on the system.</p>
|
||
|
<p>To create an external procedure or an SQL procedure, you can use the SQL
|
||
|
CREATE PROCEDURE statement. </p>
|
||
|
<p>The following sections describe the SQL statements used to define and call
|
||
|
the stored procedure, information about passing parameters to the stored procedure,
|
||
|
and examples of stored procedure usage. </p>
|
||
|
<p>For more information about stored procedures, see <a href="http://www.redbooks.ibm.com/abstracts/sg246503.html?Open">Stored
|
||
|
Procedures, Triggers and User Defined Functions on DB2 Universal Database
|
||
|
for iSeries PDF</a><img src="www.gif" alt="Link outside information center" /></p>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="rbafydfnid.htm">Define an external procedure</a></strong><br />
|
||
|
The CREATE PROCEDURE statement for an external procedure names the procedure, defines the parameters and their attributes, and gives other information about the procedure that the system uses when it calls the procedure.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafysqlproc.htm">Define an SQL procedure</a></strong><br />
|
||
|
The CREATE PROCEDURE statement for SQL procedures names the procedure,
|
||
|
defines the parameters and their attributes, provides other information about
|
||
|
the procedure that is used when the procedure is called, and defines the procedure
|
||
|
body. The <dfn class="term">procedure body</dfn> is the executable part of the procedure
|
||
|
and is a single SQL statement.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyinvokeproc.htm">Invoke a stored procedure</a></strong><br />
|
||
|
The SQL CALL statement calls a stored procedure.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyresultsets.htm">Return result sets from stored procedures</a></strong><br />
|
||
|
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.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyppcsp.htm">Parameter passing conventions for stored procedures and UDFs</a></strong><br />
|
||
|
The CALL statement and a function call can pass arguments to programs written in all supported host languages and REXX procedures.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyindicator.htm">Indicator variables and stored procedures</a></strong><br />
|
||
|
Indicator variables can be used with the CALL statement, provided host variables are used for the parameters, to pass additional information to and from the procedure.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyreturningstatus.htm">Return a completion status to the calling program</a></strong><br />
|
||
|
For SQL procedures, any errors that are not handled in the procedure are returned to the caller in the SQLCA.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyroutines.htm" title="Routines are pieces of code or programs that you can call to perform operations.">Routines</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="rbafystored1.htm" title="A stored procedure is a program that can be called using the SQL CALL statement.">Stored procedures</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="rbafydrdastoredproc.htm" title="The iSeries DRDA server supports the return of one or more result sets from a stored procedure.">DRDA stored procedure considerations</a></div>
|
||
|
</div>
|
||
|
<div class="relinfo"><strong>Related information</strong><br />
|
||
|
<div><a href="../db2/rbafzmstcreatep.htm">CREATE PROCEDURE statement</a></div>
|
||
|
<div><a href="../rzaha/jsqlrout.htm">Java SQL Routines</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|