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

91 lines
5.9 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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="Use a cursor" />
<meta name="abstract" content="When SQL runs a select statement, the resulting rows comprise the result table. A cursor provides a way to access a result table." />
<meta name="description" content="When SQL runs a select statement, the resulting rows comprise the result table. A cursor provides a way to access a result table." />
<meta name="DC.subject" content="cursor, using" />
<meta name="keywords" content="cursor, using" />
<meta name="DC.Relation" scheme="URI" content="rbafydynamic.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafycursortype.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafycursorexamp.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafymrfetch.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafycmprec.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafyupdatingasretrieved.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmsth2clcu.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstclosst.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstfets.htm#fets" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstdelst.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstupdt.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="rbafycurs" />
<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>Use a cursor</title>
</head>
<body id="rbafycurs"><a name="rbafycurs"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Use a cursor</h1>
<div><p>When SQL runs a select statement, the resulting rows comprise the
result table. A cursor provides a way to access a result table.</p>
<div class="section"><p>It is used within an SQL program to maintain a position in the
result table. SQL uses a cursor to work with the rows in the result table
and to make them available to your program. Your program can have several
cursors, although each must have a unique name.</p>
</div>
<div class="section"><p>Statements related to using a cursor include the following: </p>
<ul><li>A DECLARE CURSOR statement to define and name the cursor and specify the
rows to be retrieved with the embedded select statement.</li>
<li>OPEN and CLOSE statements to open and close the cursor for use within
the program. The cursor must be opened before any rows can be retrieved.</li>
<li>A FETCH statement to retrieve rows from the cursor's result table or to
position the cursor on another row.</li>
<li>An UPDATE ... WHERE CURRENT OF statement to update the current row of
a cursor.</li>
<li>A DELETE ... WHERE CURRENT OF statement to delete the current row of a
cursor.</li>
</ul>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rbafycursortype.htm">Types of cursors</a></strong><br />
SQL supports serial and scrollable cursors. The type of cursor determines the positioning methods which can be used with the cursor.</li>
<li class="ulchildlink"><strong><a href="rbafycursorexamp.htm">Examples: Use a cursor</a></strong><br />
Suppose your program examines data about people in department D11. The following examples show the SQL statements you would include in a program to define and use a serial and a scrollable cursor.</li>
<li class="ulchildlink"><strong><a href="rbafymrfetch.htm">Use the multiple-row FETCH statement</a></strong><br />
The multiple-row FETCH statement can be used to retrieve multiple rows from a table or view with a single FETCH. The program controls the blocking of rows by the number of rows requested on the FETCH statement (OVRDBF has no effect).</li>
<li class="ulchildlink"><strong><a href="rbafycmprec.htm">Unit of work and open cursors</a></strong><br />
When your program completes a unit of work, it should commit or roll back the changes you made.</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="relref"><strong>Related reference</strong><br />
<div><a href="rbafyupdatingasretrieved.htm" title="You can update rows of data as you retrieve them by using a cursor.">Update data as it is retrieved from a table</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../db2/rbafzmsth2clcu.htm">DECLARE CURSOR statement</a></div>
<div><a href="../db2/rbafzmstclosst.htm">CLOSE statement</a></div>
<div><a href="../db2/rbafzmstfets.htm#fets">FETCH statement</a></div>
<div><a href="../db2/rbafzmstdelst.htm">DELETE statement</a></div>
<div><a href="../db2/rbafzmstupdt.htm">UPDATE statement</a></div>
</div>
</div>
</body>
</html>