137 lines
7.2 KiB
HTML
137 lines
7.2 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="CLOSE statement, CLOSE, SQL statements, closing,
|
|
cursor, in CLOSE statement, cursor-name" />
|
|
<title>CLOSE</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="closst"></a>
|
|
<h2 id="closst"><a href="rbafzmst02.htm#ToC_800">CLOSE</a></h2><a id="idx1513" name="idx1513"></a><a id="idx1514" name="idx1514"></a><a id="idx1515" name="idx1515"></a>
|
|
<p>The CLOSE statement closes a cursor. If a result table was created when
|
|
the cursor was opened, that table is destroyed.</p>
|
|
<a name="wq1138"></a>
|
|
<h3 id="wq1138"><a href="rbafzmst02.htm#ToC_801">Invocation</a></h3>
|
|
<p>This statement can only be embedded in an application program. It is an
|
|
executable statement that cannot be dynamically prepared. It must not be specified
|
|
in Java™.</p>
|
|
<a name="wq1139"></a>
|
|
<h3 id="wq1139"><a href="rbafzmst02.htm#ToC_802">Authorization</a></h3>
|
|
<p>None required. See <a href="rbafzmsth2clcu.htm#h2dclcu">DECLARE CURSOR</a> for the authorization required
|
|
to use a cursor.</p>
|
|
<a name="wq1140"></a>
|
|
<h3 id="wq1140"><a href="rbafzmst02.htm#ToC_803">Syntax</a></h3>
|
|
<a href="rbafzmstclosst.htm#synsclose"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn261.htm"
|
|
border="0" /></span><a href="#skipsyn-260"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-CLOSE--<span class="italic">cursor-name</span>------------------------------------------><
|
|
|
|
</pre>
|
|
<a name="skipsyn-260" id="skipsyn-260"></a>
|
|
<a name="synsclose"></a>
|
|
<h3 id="synsclose"><a href="rbafzmst02.htm#ToC_804">Description</a></h3>
|
|
<dl class="parml">
|
|
<dt class="bold"><var class="pv">cursor-name</var> </dt><a id="idx1516" name="idx1516"></a>
|
|
<dd>Identifies the cursor to be closed. The <span class="italic">cursor-name</span> must identify a declared cursor as explained in the DECLARE CURSOR statement.
|
|
When the CLOSE statement is executed, the cursor must be in the open state.
|
|
</dd>
|
|
</dl>
|
|
<a name="wq1141"></a>
|
|
<h3 id="wq1141"><a href="rbafzmst02.htm#ToC_805">Notes</a></h3>
|
|
<p><span class="bold">Implicit cursor close:</span> All cursors in a program are
|
|
in the closed state when: </p>
|
|
<ul>
|
|
<li>The program is called.
|
|
<ul>
|
|
<li>If CLOSQLCSR(*ENDPGM) is specified, all cursors are in the closed state
|
|
each time the program is called.</li>
|
|
<li>If CLOSQLCSR(*ENDSQL) is specified, all cursors are in the closed state
|
|
only the first time the program is called as long as one SQL program remains
|
|
on the call stack.</li>
|
|
<li>If CLOSQLCSR(*ENDJOB) is specified, all cursors are in the closed state
|
|
only the first time the program is called in the job.</li>
|
|
<li>If CLOSQLCSR(*ENDMOD) is specified, all cursors are in the closed state
|
|
each time the module is initiated.</li>
|
|
<li>If CLOSQLCSR(*ENDACTGRP) is specified, all cursors are in the closed state
|
|
the first time the module in the program is initiated within the activation
|
|
group.</li></ul></li>
|
|
<li>A program starts a new unit of work by executing a COMMIT or ROLLBACK
|
|
statement without a HOLD option. Cursors declared with the HOLD option are
|
|
not closed by a COMMIT statement.</li></ul><p class="indatacontent"> </p>
|
|
<a name="wq1142"></a>
|
|
<div class="notetitle" id="wq1142">Note:</div>
|
|
<div class="notebody">The DB2 UDB for iSeries database manager will open files in order
|
|
to implement queries. The closing of the files can be separate from the SQL
|
|
CLOSE statement. For more information, see the <a href="../sqlp/rbafykickoff.htm">SQL Programming</a> book.</div>
|
|
<p><span class="bold">Close cursors for performance:</span> Explicitly closing
|
|
cursors as soon as possible can improve performance.</p>
|
|
<p><span class="bold">Procedure considerations:</span> Special rules apply to
|
|
cursors within procedures that have not been closed before returning to the
|
|
calling program. For more information, see <a href="rbafzmstcallsta.htm#callsta">CALL</a>.</p>
|
|
<a name="wq1143"></a>
|
|
<h3 id="wq1143"><a href="rbafzmst02.htm#ToC_806">Example</a></h3>
|
|
<p>In a COBOL program, use the cursor C1 to fetch the values from the first
|
|
four columns of the EMPPROJACT table a row at a time and put them in the following
|
|
host variables: </p>
|
|
<ul>
|
|
<li>EMP (CHAR(6))</li>
|
|
<li>PRJ (CHAR(6))</li>
|
|
<li>ACT (SMALLINT)</li>
|
|
<li>TIM (DECIMAL(5,2))</li></ul><p class="indatacontent"> Finally, close the cursor. </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) BINARY.
|
|
77 TIM PIC S9(3)V9(2) PACKED-DECIMAL.
|
|
EXEC SQL <span class="bold">END DECLARE SECTION</span> END-EXEC.
|
|
.
|
|
.
|
|
.
|
|
|
|
EXEC SQL <span class="bold">DECLARE</span> C1 <span class="bold">CURSOR FOR</span>
|
|
<span class="bold">SELECT</span> EMPNO, PROJNO, ACTNO, EMPTIME
|
|
<span class="bold">FROM</span> EMPPROJACT END-EXEC.
|
|
|
|
EXEC SQL <span class="bold">OPEN</span> C1 END-EXEC.
|
|
|
|
EXEC SQL <span class="bold">FETCH</span> C1 <span class="bold">INTO</span> :EMP, :PRJ, :ACT, :TIM END-EXEC.
|
|
|
|
IF SQLSTATE = '02000'
|
|
PERFORM DATA-NOT-FOUND
|
|
ELSE
|
|
PERFORM GET-REST-OF-ACTIVITY UNTIL SQLSTATE IS NOT EQUAL TO '00000'.
|
|
|
|
EXEC SQL <span class="bold">CLOSE</span> C1 END-EXEC.
|
|
|
|
GET-REST-OF-ACTIVITY
|
|
EXEC SQL <span class="bold">FETCH</span> C1 <span class="bold">INTO</span> :EMP, :PRJ, :ACT, :TIM END-EXEC.
|
|
.
|
|
.
|
|
.</pre><a id="idx1517" name="idx1517"></a><a id="idx1518" name="idx1518"></a>
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstcallsta.htm">Previous Page</a> | <a href="rbafzmstcomnt.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>
|