123 lines
7.6 KiB
HTML
123 lines
7.6 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="Parameter markers" />
|
|
<meta name="abstract" content="In the example used, the SELECT statement that was dynamically run had a constant value in the WHERE clause." />
|
|
<meta name="description" content="In the example used, the SELECT statement that was dynamically run had a constant value in the WHERE clause." />
|
|
<meta name="DC.subject" content="parameter markers, in dynamic SQL, WHERE clause, example, dynamic SQL, clause, WHERE, dynamic SQL example, OPEN statement, statements, OPEN, parameter marker, USING, DESCRIPTOR clause, USING DESCRIPTOR, replacing parameter markers with host variables" />
|
|
<meta name="keywords" content="parameter markers, in dynamic SQL, WHERE clause, example, dynamic SQL, clause, WHERE, dynamic SQL example, OPEN statement, statements, OPEN, parameter marker, USING, DESCRIPTOR clause, USING DESCRIPTOR, replacing parameter markers with host variables" />
|
|
<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="rbafypmaker" />
|
|
<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>Parameter markers</title>
|
|
</head>
|
|
<body id="rbafypmaker"><a name="rbafypmaker"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Parameter markers</h1>
|
|
<div><p>In the example used, the SELECT statement that was dynamically
|
|
run had a constant value in the WHERE clause.</p>
|
|
<div class="section"><p>In the example, it was:</p>
|
|
<pre> <strong>WHERE</strong> LASTNAME = 'PARKER'</pre>
|
|
</div>
|
|
<div class="section"><p>If you want to run the same SELECT statement several times, using
|
|
different values for LASTNAME, you can use an SQL statement that looks like
|
|
this:</p>
|
|
<pre> <strong>SELECT</strong> WORKDEPT, PHONENO
|
|
<strong>FROM</strong> CORPDATA.EMPLOYEE
|
|
<strong>WHERE</strong> LASTNAME = ?</pre>
|
|
</div>
|
|
<div class="section"><p><img src="./delta.gif" alt="Start of change" />When using parameter markers, your application
|
|
does not need to set the data types and values for the parameters until run
|
|
time. By specifying a descriptor on the OPEN statement, you can substitute
|
|
the values for the parameter markers in the SELECT statement.<img src="./deltaend.gif" alt="End of change" /></p>
|
|
</div>
|
|
<div class="section"><p><img src="./delta.gif" alt="Start of change" />To code such a program, you need to use the OPEN
|
|
statement with a descriptor clause. This SQL statement is used to not only
|
|
open a cursor, but to replace each parameter marker with the value of the
|
|
corresponding descriptor entry. The descriptor name that you specify with
|
|
this statement must identify a descriptor that contains a valid definition
|
|
of the values. This descriptor is not used to return information about data
|
|
items that are part of a SELECT list. It provides information about values
|
|
that are used to replace parameter markers in the SELECT statement. It gets
|
|
this information from the application, which must be designed to place appropriate
|
|
values into the fields of the descriptor. The descriptor is then ready to
|
|
be used by SQL for replacing parameter markers with the actual values.<img src="./deltaend.gif" alt="End of change" /></p>
|
|
</div>
|
|
<div class="section"><p>When you use an SQLDA for input to the OPEN statement
|
|
with the USING DESCRIPTOR clause, not all of its fields need to be filled
|
|
in. Specifically, SQLDAID, SQLRES, and SQLNAME can be left blank (SQLNAME
|
|
can be set if a specific CCSID is needed.) Therefore, when you use this method
|
|
for replacing parameter markers with values, you need to determine:</p>
|
|
<ul><li>How many parameter markers there are</li>
|
|
<li>The data types and attributes of these parameters markers (SQLTYPE, SQLLEN,
|
|
and SQLNAME)</li>
|
|
<li>Whether an indicator variable is needed</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section"><p><img src="./delta.gif" alt="Start of change" />In addition, if the routine is to handle both
|
|
SELECT and non-SELECT statements, you might want to determine what category
|
|
of statement it is.<img src="./deltaend.gif" alt="End of change" /></p>
|
|
</div>
|
|
<div class="section"><p>If your application uses parameter markers, your program has to
|
|
perform the following steps. This can be done using either an SQLDA or an
|
|
allocated descriptor.</p>
|
|
</div>
|
|
<div class="section"> <ol><li>Read a statement into the DSTRING varying-length character string host
|
|
variable.</li>
|
|
<li>Determine the number of parameter markers.</li>
|
|
<li>Allocate an SQLDA of that size or use ALLOCATE DESCRIPTOR to allocate
|
|
a descriptor with that number of entries. This is not applicable in REXX.</li>
|
|
<li>For an SQLDA, set SQLN and SQLD to the number of parameter markers. SQLN
|
|
is not applicable in REXX. For an allocated descriptor, use SET DESCRIPTOR
|
|
to set the COUNT entry to the number of parameter markers. </li>
|
|
<li>For an SQLDA, set SQLDABC equal to SQLN*LENGTH(SQLVAR) + 16. This is not
|
|
applicable in REXX.</li>
|
|
<li>For each parameter marker:<ol type="a"><li>Determine the data types, lengths, and indicators.</li>
|
|
<li>For an SQLDA, set SQLTYPE and SQLLEN for each parameter marker. For an
|
|
allocated descriptor, use SET DESCRIPTOR to set the entries for TYPE, LENGTH,
|
|
PRECISION, and SCALE for each parameter marker. </li>
|
|
<li>For an SQLDA, allocate storage to hold the input values.</li>
|
|
<li>For an SQLDA, set these values in storage.</li>
|
|
<li>For an SQLDA, set SQLDATA and SQLIND (if applicable) for each parameter
|
|
marker. For an allocated descriptor, use SET DESCRIPTOR to set entries for
|
|
DATA and INDICATOR (if applicable) for each parameter marker. </li>
|
|
<li>If character variables are used and they have a CCSID other
|
|
than the job default CCSID, or graphic variables are used and they have a
|
|
CCSID other than the associated DBCS CCSID for the job CCSID,<ul><li>For an SQLDA, set SQLNAME (SQLCCSID in REXX) accordingly.</li>
|
|
<li>For an allocated SQL descriptor, use SET DESCRIPTOR to set the DB2_CCSID
|
|
value.</li>
|
|
</ul>
|
|
</li>
|
|
<li>Issue the OPEN statement with a USING DESCRIPTOR clause (for an SQLDA)
|
|
or USING SQL DESCRIPTOR clause (for an allocated descriptor) to open your
|
|
cursor and substitute values for each of the parameter markers.</li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
<div class="section"><p>The statement can then be processed normally.</p>
|
|
</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> |