112 lines
8.8 KiB
HTML
112 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="Dynamic SQL applications" />
|
||
|
<meta name="abstract" content="Dynamic SQL allows an application to define and run SQL statements at program run time. An application that provides for dynamic SQL accepts as input (or builds) an SQL statement in the form of a character string. The application does not need to know what type of SQL statement it will run." />
|
||
|
<meta name="description" content="Dynamic SQL allows an application to define and run SQL statements at program run time. An application that provides for dynamic SQL accepts as input (or builds) an SQL statement in the form of a character string. The application does not need to know what type of SQL statement it will run." />
|
||
|
<meta name="DC.subject" content="dynamic SQL, application, overview, building and running statements, run-time overhead, address variable, SELECT INTO statement, in dynamic SQL, statements, SELECT INTO" />
|
||
|
<meta name="keywords" content="dynamic SQL, application, overview, building and running statements, run-time overhead, address variable, SELECT INTO statement, in dynamic SQL, statements, SELECT INTO" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydynamic.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafydesignapp.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyccsiddyn.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafynonsil.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyprocesssqlda.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafycmprec.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyintract.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafyplepexc.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafynonsil.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rbafynonsil.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstactallow.htm#actallow" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="../apis/qsqprced.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="rbafydynmic" />
|
||
|
<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>Dynamic SQL applications</title>
|
||
|
</head>
|
||
|
<body id="rbafydynmic"><a name="rbafydynmic"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Dynamic SQL applications</h1>
|
||
|
<div><p>Dynamic SQL allows an application to define and run SQL statements
|
||
|
at program run time. An application that provides for dynamic SQL accepts
|
||
|
as input (or builds) an SQL statement in the form of a character string. The
|
||
|
application does not need to know what type of SQL statement it will run.</p>
|
||
|
<p>The application:</p>
|
||
|
<ul><li>Builds or accepts as input an SQL statement</li>
|
||
|
<li>Prepares the SQL statement for running</li>
|
||
|
<li>Runs the statement</li>
|
||
|
<li>Handles SQL return codes</li>
|
||
|
</ul>
|
||
|
<p>Interactive SQL is an example of a dynamic SQL program. SQL statements
|
||
|
are processed and run dynamically by interactive SQL. </p>
|
||
|
<div class="note"><span class="notetitle">Notes:</span> <ol><li><img src="./delta.gif" alt="Start of change" />The processing of dynamic SQL can have substantially
|
||
|
higher overhead than that for static SQL because the statement may need to
|
||
|
be fully processed at run time. In the worst case, the statement must be fully
|
||
|
prepared, bound, and optimized by the database before it is run. In many other
|
||
|
cases, if the statement has been run before, parts of the processing can be
|
||
|
skipped because of the algorithms used and caches maintained by the database.
|
||
|
These features allow DB2 for <span class="keyword">iSeries™</span> to
|
||
|
provide good performance for dynamic SQL statements. If performance for your
|
||
|
dynamic application is critical, consider using the extended dynamic capability
|
||
|
using the QSQPRCED API. This feature allows the application to maintain a
|
||
|
persistent cache of SQL statements and substantially reduces runtime overhead
|
||
|
when running the application.<img src="./deltaend.gif" alt="End of change" /></li>
|
||
|
<li>Programs that contain an EXECUTE or EXECUTE IMMEDIATE statement and that
|
||
|
use a FOR READ ONLY clause to make a cursor read-only experience better performance
|
||
|
because blocking is used to retrieve rows for the cursor. <p>The ALWBLK(*ALLREAD)
|
||
|
CRTSQLxxx option will imply a FOR READ ONLY declaration for all cursors that
|
||
|
do not explicitly code FOR UPDATE OF or have positioned deletes or updates
|
||
|
that refer to the cursor. Cursors with an implied FOR READ ONLY will benefit
|
||
|
from the second item in this list.</p>
|
||
|
</li>
|
||
|
</ol>
|
||
|
</div>
|
||
|
<p>Some dynamic SQL statements require use of address variables. RPG/400 programs
|
||
|
require the aid of PL/I, COBOL, C, or ILE RPG programs to manage the address
|
||
|
variables.</p>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="rbafydesignapp.htm">Design and run a dynamic SQL application</a></strong><br />
|
||
|
To issue a dynamic SQL statement, you must use the statement with either an EXECUTE statement or an EXECUTE IMMEDIATE statement, because dynamic SQL statements are not prepared at precompile time and therefore must be prepared at run time. The EXECUTE IMMEDIATE statement causes the SQL statement to be prepared and run dynamically at program run time.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyccsiddyn.htm">CCSID of dynamic SQL statements</a></strong><br />
|
||
|
The SQL statement is normally a host variable. The CCSID of the host variable is used as the CCSID of the statement text. In PL/I, it also can be a string expression. In this case, the job CCSID is used as the CCSID of the statement text.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafynonsil.htm">Process non-SELECT statements</a></strong><br />
|
||
|
To build a dynamic SQL non-SELECT statement, you need to verify that the SQL statement you want to build is one that can be run dynamically and then build the SQL statement.</li>
|
||
|
<li class="ulchildlink"><strong><a href="rbafyprocesssqlda.htm">Process SELECT statements and use a descriptor</a></strong><br />
|
||
|
There are two basic types of SELECT statements: <strong>fixed list</strong> and <strong>varying
|
||
|
list</strong>. </li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafydynamic.htm" title="You can use SQL in many different environments. Some of them are discussed here.">Use SQL in different environments</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="rbafyintract.htm" title="Interactive SQL allows the programmer or database administrator to quickly and easily define, update, delete, or look at data for testing, problem analysis, and database maintenance.">Use interactive SQL</a></div>
|
||
|
</div>
|
||
|
<div class="relref"><strong>Related reference</strong><br />
|
||
|
<div><a href="rbafycmprec.htm" title="When your program completes a unit of work, it should commit or roll back the changes you made.">Unit of work and open cursors</a></div>
|
||
|
<div><a href="rbafyplepexc.htm" title="If non-SELECT statements contain no parameter markers, they can be run dynamically using the EXECUTE IMMEDIATE statement. However, if the non-SELECT statements have parameter markers, they must be run using PREPARE and EXECUTE.">Use the PREPARE and EXECUTE statements</a></div>
|
||
|
<div><a href="rbafynonsil.htm" title="To build a dynamic SQL non-SELECT statement, you need to verify that the SQL statement you want to build is one that can be run dynamically and then build the SQL statement.">Process non-SELECT statements</a></div>
|
||
|
<div><a href="../apis/qsqprced.htm">Process Extended Dynamic SQL (QSQPRCED) API</a></div>
|
||
|
</div>
|
||
|
<div class="relinfo"><strong>Related information</strong><br />
|
||
|
<div><a href="../db2/rbafzmstactallow.htm#actallow">Actions allowed on SQL statements</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|