255 lines
14 KiB
HTML
255 lines
14 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="EXECUTE statement, EXECUTE, SQL statements,
|
|
executing, prepared SQL statement, execution, dynamic SQL, in EXECUTE statement,
|
|
statement-name, USING clause, parameter marker, question mark (?),
|
|
? (question mark), substitution for parameter markers, variable, INTO keyword,
|
|
SQL-descriptor-name, in OPEN statement, USING DESCRIPTOR clause, descriptor-name,
|
|
replacement" />
|
|
<title>EXECUTE</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="hexeqt"></a>
|
|
<h2 id="hexeqt"><a href="rbafzmst02.htm#ToC_1057">EXECUTE</a></h2><a id="idx2541" name="idx2541"></a><a id="idx2542" name="idx2542"></a><a id="idx2543" name="idx2543"></a><a id="idx2544" name="idx2544"></a>
|
|
<a name="exeqt"></a>
|
|
<p id="exeqt">The EXECUTE statement executes a prepared SQL statement.</p>
|
|
<a name="wq1484"></a>
|
|
<h3 id="wq1484"><a href="rbafzmst02.htm#ToC_1058">Invocation</a></h3>
|
|
<p>This statement can only be embedded in an application program,
|
|
SQL function, SQL procedure, or trigger. It is an executable statement that
|
|
cannot be dynamically prepared. It must not be specified in Java™.</p>
|
|
<a name="wq1485"></a>
|
|
<h3 id="wq1485"><a href="rbafzmst02.htm#ToC_1059">Authorization</a></h3>
|
|
<p>The authorization rules are those defined for the SQL statement specified
|
|
by EXECUTE. For example, see the description of INSERT for the authorization
|
|
rules that apply when an INSERT statement is executed using EXECUTE.</p>
|
|
<p>The authorization ID of the statement is the run-time authorization ID
|
|
unless DYNUSRPRF(*OWNER) was specified on the CRTSQLxxx command when the program
|
|
was created. For more information, see <a href="rbafzmstch2auth.htm#ch2auth">Authorization IDs and authorization names</a>.</p>
|
|
<a name="wq1486"></a>
|
|
<h3 id="wq1486"><a href="rbafzmst02.htm#ToC_1060">Syntax</a></h3>
|
|
<a href="rbafzmsthexeqt.htm#synsexecute"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn338.htm"
|
|
border="0" /></span><a href="#skipsyn-337"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-EXECUTE--<span class="italic">statement-name</span>-------------------------------------->
|
|
|
|
>--+-----------------------------------+-----------------------><
|
|
| .-,--------. |
|
|
| V | |
|
|
+-USING----<span><span class="italic">variable</span></span>-+---------------+
|
|
+-<span class="italic">SQL-descriptors</span>-------------------+
|
|
'-USING DESCRIPTOR--<span class="italic">descriptor-name</span>-'
|
|
|
|
SQL-descriptors:
|
|
|
|
|--+------------------------------------------------------------+-->
|
|
| .-SQL-. .-LOCAL--. |
|
|
'-INTO--+-----+--DESCRIPTOR--+--------+--<span class="italic">SQL-descriptor-name</span>-'
|
|
'-GLOBAL-'
|
|
|
|
>--+------------------------------------------------------------------+--|
|
|
| (1) |
|
|
| .-SQL------. .-LOCAL--. |
|
|
'-USING--+----------+--DESCRIPTOR--+--------+--<span class="italic">SQL-descriptor-name</span>-'
|
|
'-GLOBAL-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-337" id="skipsyn-337"></a>
|
|
<a name="wq1487"></a>
|
|
<div class="notelisttitle" id="wq1487">Notes:</div>
|
|
<ol type="1">
|
|
<li>If an SQL descriptor is specified in the USING clause and the INTO
|
|
clause is not specified, USING DESCRIPTOR is not allowed and USING SQL DESCRIPTOR
|
|
must be specified.</li>
|
|
</ol>
|
|
<a name="synsexecute"></a>
|
|
<h3 id="synsexecute"><a href="rbafzmst02.htm#ToC_1061">Description</a></h3>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">statement-name</var> </dt><a id="idx2545" name="idx2545"></a>
|
|
<dd>Identifies the prepared statement to be executed. <var class="pv">Statement-name</var> must identify a statement that was previously prepared. The prepared
|
|
statement cannot be a SELECT statement.
|
|
</dd>
|
|
<dt class="bold"><span class="pk">USING</span> </dt><a id="idx2546" name="idx2546"></a><a id="idx2547" name="idx2547"></a><a id="idx2548" name="idx2548"></a><a id="idx2549" name="idx2549"></a><a id="idx2550" name="idx2550"></a>
|
|
<dd>Introduces a list of variables whose values are substituted for the
|
|
parameter markers (question marks) in the prepared statement. For an explanation
|
|
of parameter markers, see <a href="rbafzmstpreph2.htm#preph2">PREPARE</a>. If the prepared statement
|
|
includes parameter markers, the USING clause must be used. USING is ignored
|
|
if there are no parameter markers.
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">variable,...</var> </dt><a id="idx2551" name="idx2551"></a>
|
|
<dd>Identifies one of more host structures or variables that must be declared
|
|
in the program in accordance with the rules for declaring host structures
|
|
and variables. A reference to a host structure is replaced by a reference
|
|
to each of its variables. The number of variables must be the same as the
|
|
number of parameter markers in the prepared statement. The <span class="italic">n</span>th variable corresponds to the <span class="italic">n</span>th parameter
|
|
marker in the prepared statement.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">SQL-descriptors</var></dt>
|
|
<dd>
|
|
<dl class="parml">
|
|
<dt class="bold">INTO<a id="idx2552" name="idx2552"></a></dt>
|
|
<dd>Identifies an SQL descriptor which contains valid descriptions of the
|
|
output variables to be used with the EXECUTE statement. This clause is only
|
|
valid for a CALL or VALUES INTO statement. Before the EXECUTE statement is
|
|
executed, a descriptor must be allocated using the ALLOCATE DESCRIPTOR statement.
|
|
<dl class="parml">
|
|
<dt class="bold">LOCAL</dt>
|
|
<dd>Specifies the scope of the name of the descriptor to be local to program
|
|
invocation.
|
|
</dd>
|
|
<dt class="bold">GLOBAL</dt>
|
|
<dd>Specifies the scope of the name of the descriptor to be global to the
|
|
SQL session.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">SQL-descriptor-name</var></dt>
|
|
<dd>Names the SQL descriptor. The name must identify a descriptor that already
|
|
exists with the specified scope. <a id="idx2553" name="idx2553"></a>
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
<dt class="bold">USING</dt>
|
|
<dd>Identifies an SQL descriptor which contains valid descriptions
|
|
of the input variables to be used with the EXECUTE statement. Before the EXECUTE
|
|
statement is executed, a descriptor must be allocated using the ALLOCATE DESCRIPTOR
|
|
statement.
|
|
<dl class="parml">
|
|
<dt class="bold">LOCAL</dt>
|
|
<dd>Specifies the scope of the name of the descriptor to be local to program
|
|
invocation. The information is returned from the descriptor known in this
|
|
local scope.
|
|
</dd>
|
|
<dt class="bold">GLOBAL</dt>
|
|
<dd>Specifies the scope of the name of the descriptor to be global to the
|
|
SQL session. The information is returned from the descriptor known to any
|
|
program that executes using the same database connection.
|
|
</dd>
|
|
<dt class="bold"><var class="pv">SQL-descriptor-name</var></dt>
|
|
<dd>Names the SQL descriptor. The name must identify a descriptor that already
|
|
exists with the specified scope. <a id="idx2554" name="idx2554"></a>
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
<dt class="bold"><span class="pk">DESCRIPTOR</span> <var class="pv">descriptor-name</var> </dt><a id="idx2555" name="idx2555"></a><a id="idx2556" name="idx2556"></a>
|
|
<dd>Identifies an SQLDA that must contain a valid description of variables.
|
|
<p>Before the EXECUTE statement is processed, the user must set the following
|
|
fields in the SQLDA. (The rules for REXX are different. For more information,
|
|
see the <a href="../rzajp/rzajpkickoff.htm">Embedded SQL Programming</a> book.) </p>
|
|
<ul>
|
|
<li>SQLN to indicate the number of SQLVAR occurrences provided in the SQLDA.</li>
|
|
<li>SQLDABC to indicate the number of bytes of storage allocated for the SQLDA.</li>
|
|
<li>SQLD to indicate the number of variables used in the SQLDA when processing
|
|
the statement.</li>
|
|
<li>SQLVAR occurrences to indicate the attributes of the variables.</li></ul>
|
|
<p>The SQLDA must have enough storage to contain all SQLVAR occurrences.
|
|
If LOBs or distinct types are present in the results, there must be additional
|
|
SQLVAR entries for each parameter. For more information about the SQLDA, which
|
|
includes a description of the SQLVAR and an explanation on how to determine
|
|
the number of SQLVAR occurrences, see <a href="rbafzmstsqldda.htm#sqldda">Appendix D. SQLDA (SQL descriptor area)</a>.</p>
|
|
<p>SQLD must
|
|
be set to a value greater than or equal to zero and less than or equal to
|
|
SQLN. It must be the same as the number of parameter markers in the prepared
|
|
statement. The <span class="italic">n</span>th variable described by the SQLDA
|
|
corresponds to the <span class="italic">n</span>th parameter marker in the prepared
|
|
statement.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>Note that RPG/400® does not provide the function for setting pointers.
|
|
Because the SQLDA uses pointers to locate the appropriate variables, you have
|
|
to set these pointers outside your RPG/400 application.</p>
|
|
</dd>
|
|
</dl>
|
|
<a name="wq1489"></a>
|
|
<h3 id="wq1489"><a href="rbafzmst02.htm#ToC_1062">Notes</a></h3><a id="idx2557" name="idx2557"></a>
|
|
<p><span class="bold">Parameter marker replacement:</span> Before the prepared
|
|
statement is executed, each parameter marker in the statement is effectively
|
|
replaced by its corresponding variable. The replacement of a parameter marker
|
|
is an assignment operation in which the source is the value of the variable,
|
|
and the target is a variable within the database manager. For a typed parameter
|
|
marker, the attributes of the target variable are those specified by the CAST
|
|
specification. For an untyped parameter marker, the attributes of the target
|
|
variable are determined according to the context of the parameter marker.
|
|
For the rules that affect parameter markers, see <a href="rbafzmstpreph2.htm#parmtbl">Table 74</a>.</p>
|
|
<p>Let V denote a variable that corresponds to parameter marker P. The value
|
|
of V is assigned to the target variable for P in accordance with the rules
|
|
for assigning a value to a column. Thus: </p>
|
|
<ul>
|
|
<li>V must be compatible with the target.</li>
|
|
<li>If V is a number, the absolute value of its integral part must not be
|
|
greater than the maximum absolute value of the integral part of the target.</li>
|
|
<li>If the attributes of V are not identical to the attributes of the target,
|
|
the value is converted to conform to the attributes of the target.</li>
|
|
<li>If the target cannot contain nulls, the value of V must not be null.</li></ul>
|
|
<p>However, unlike the rules for assigning a value to a column: </p>
|
|
<ul>
|
|
<li>If V is a string, the value will be truncated (without an error), if its
|
|
length is greater than the length attribute of the target.</li></ul>
|
|
<p>When the prepared statement is executed, the value used in place of P is
|
|
the value of the target variable for P. For example, if V is CHAR(6) and the
|
|
target is CHAR(8), the value used in place of P is the value of V padded with
|
|
two blanks.</p>
|
|
<a name="wq1490"></a>
|
|
<h3 id="wq1490"><a href="rbafzmst02.htm#ToC_1063">Example</a></h3>
|
|
<p>This example of portions of a COBOL program shows how an INSERT statement
|
|
with parameter markers is prepared and executed. </p>
|
|
<pre class="xmp"> EXEC SQL <span class="bold">BEGIN DECLARE SECTION</span> END-EXEC.
|
|
77 EMP PIC X(6).
|
|
77 PRJ PIC X(6).
|
|
77 ACT PIC S9(4) COMP-4.
|
|
77 TIM PIC S9(3)V9(2).
|
|
01 HOLDER.
|
|
49 HOLDER-LENGTH PIC S9(4) COMP-4.
|
|
49 HOLDER-VALUE PIC X(80).
|
|
EXEC SQL <span class="bold">END DECLARE SECTION</span> END-EXEC.
|
|
.
|
|
.
|
|
.
|
|
MOVE 70 TO HOLDER-LENGTH.
|
|
MOVE <span class="bold">"INSERT INTO</span> EMPPROJACT <span class="bold">(</span>EMPNO, PROJNO, ACTNO, EMPTIME<span class="bold">)</span>
|
|
<span class="bold">- "VALUES (?, ?, ?, ?)"</span> TO HOLDER-VALUE.
|
|
EXEC SQL <span class="bold">PREPARE</span> MYINSERT <span class="bold">FROM</span> :HOLDER END-EXEC.
|
|
|
|
IF SQLCODE = 0
|
|
PERFORM DO-INSERT THRU END-DO-INSERT
|
|
ELSE
|
|
PERFORM ERROR-CONDITION.
|
|
|
|
DO-INSERT.
|
|
MOVE "000010" TO EMP.
|
|
MOVE "AD3100" TO PRJ.
|
|
MOVE 160 TO ACT.
|
|
MOVE .50 TO TIM.
|
|
EXEC SQL <span class="bold">EXECUTE</span> MYINSERT <span class="bold">USING</span> :EMP, :PRJ, :ACT, :TIM END-EXEC.
|
|
END-DO-INSERT.
|
|
.
|
|
.
|
|
.</pre><a id="idx2558" name="idx2558"></a><a id="idx2559" name="idx2559"></a><a id="idx2560" name="idx2560"></a>
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmsteds.htm">Previous Page</a> | <a href="rbafzmstexim.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>
|