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

94 lines
5.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="Fixed-list SELECT statements" />
<meta name="abstract" content="In dynamic SQL, fixed-list SELECT statements are those statements designed to retrieve data of a predictable number and type. When using these statements, you can anticipate and define host variables to accommodate the retrieved data so that an SQL descriptor area (SQLDA) is not necessary." />
<meta name="description" content="In dynamic SQL, fixed-list SELECT statements are those statements designed to retrieve data of a predictable number and type. When using these statements, you can anticipate and define host variables to accommodate the retrieved data so that an SQL descriptor area (SQLDA) is not necessary." />
<meta name="DC.subject" content="dynamic SQL, fixed-list SELECT statement, SELECT statement, using fixed-list, cursor, use in" />
<meta name="keywords" content="dynamic SQL, fixed-list SELECT statement, SELECT statement, using fixed-list, cursor, use in" />
<meta name="DC.Relation" scheme="URI" content="rbafyprocesssqlda.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="rbafyfixed" />
<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>Fixed-list SELECT statements</title>
</head>
<body id="rbafyfixed"><a name="rbafyfixed"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Fixed-list SELECT statements</h1>
<div><p>In dynamic SQL, fixed-list SELECT statements are those statements
designed to retrieve data of a predictable number and type. When using these
statements, you can anticipate and define host variables to accommodate the
retrieved data so that an SQL descriptor area (SQLDA) is not necessary.</p>
<div class="section"><p>Each successive FETCH returns the same number of values as the
last, and these values have the same data formats as those returned for the
last FETCH. You can specify host variables in the same manner as for any SQL
application.</p>
</div>
<div class="section"><p>You can use fixed-list dynamic SELECT statements with any SQL-supported
application program.</p>
</div>
<div class="section"><p>To run fixed-list SELECT statements dynamically, your application
must: </p>
</div>
<div class="section"> <ol><li>Place the input SQL statement into a host variable.</li>
<li>Issue a PREPARE statement to validate the dynamic SQL statement and put
it into a form that can be run. If DLYPRP (*YES) is specified on the CRTSQLxxx
command, the preparation is delayed until the first time the statement is
used in an EXECUTE or DESCRIBE statement, unless the USING clause is specified
on the PREPARE statement.</li>
<li>Declare a cursor for the statement name.</li>
<li>Open the cursor.</li>
<li>FETCH a row into a fixed list of variables (rather than into a descriptor
area, as if you were using a varying-list SELECT statement.</li>
<li>When end of data occurs, close the cursor.</li>
<li>Handle any SQL return codes that result.</li>
</ol>
</div>
<div class="section"><p>For example: </p>
<pre> MOVE '<strong>SELECT</strong> EMPNO, LASTNAME <strong>FROM</strong> CORPDATA.EMPLOYEE <strong>WHERE</strong> EMPNO&gt;?'
TO DSTRING.
EXEC SQL
<strong>PREPARE</strong> S2 <strong>FROM</strong> :DSTRING END-EXEC.
EXEC SQL
<strong>DECLARE</strong> C2 <strong>CURSOR FOR</strong> S2 END-EXEC.
EXEC SQL
<strong>OPEN</strong> C2 <strong>USING</strong> :EMP END-EXEC.
PERFORM FETCH-ROW UNTIL SQLCODE NOT=0.
EXEC SQL
<strong>CLOSE</strong> C2 END-EXEC.
STOP-RUN.
FETCH-ROW.
EXEC SQL
<strong>FETCH</strong> C2 <strong>INTO</strong> :EMP, :EMPNAME END-EXEC.</pre>
<div class="note"><span class="notetitle">Note:</span> <img src="./delta.gif" alt="Start of change" />Remember
that because the SELECT statement, in this case, always returns the same number
and type of data items as previously run fixed-list SELECT statements, you
do not need to use an SQL descriptor area.<img src="./deltaend.gif" alt="End of change" /></div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyprocesssqlda.htm" title="There are two basic types of SELECT statements: fixed list and varying list.">Process SELECT statements and use a descriptor</a></div>
</div>
</div>
</body>
</html>