doc-exports/docs/dws/dev/dws_06_0216.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

103 lines
22 KiB
HTML

<a name="EN-US_TOPIC_0000001233430205"></a><a name="EN-US_TOPIC_0000001233430205"></a>
<h1 class="topictitle1">FETCH</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001233430205__s8ed10305f98a43bab3cb625c15fea37f"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001233430205__a55ceb149589c496bbc470d191ae32d0f"><strong id="EN-US_TOPIC_0000001233430205__b2409443710207">FETCH</strong> retrieves data using a previously-created cursor.</p>
<p id="EN-US_TOPIC_0000001233430205__a0cbab44241a747fb98fb5a50cb963c41">A cursor has an associated position, which is used by <strong id="EN-US_TOPIC_0000001233430205__b549238410207">FETCH</strong>. The cursor position can be before the first row of the query result, on any particular row of the result, or after the last row of the result.</p>
<ul id="EN-US_TOPIC_0000001233430205__u9d048b27336e4e56b546ffccf9b77f6e"><li id="EN-US_TOPIC_0000001233430205__l2becaafcf958416da7a9986b19bb37e8">When created, a cursor is positioned before the first row.</li><li id="EN-US_TOPIC_0000001233430205__ldc21bd12b14b40708295abf9a304919f">After fetching some rows, the cursor is positioned on the row most recently retrieved.</li><li id="EN-US_TOPIC_0000001233430205__le6ec98f3fc8e4cfd8c48e3c116c91914">If <strong id="EN-US_TOPIC_0000001233430205__b4976315510207">FETCH</strong> runs off the end of the available rows then the cursor is left positioned after the last row, or before the first row if fetching backward.</li><li id="EN-US_TOPIC_0000001233430205__la4f342bea8704f05859b3070b30dea05"><strong id="EN-US_TOPIC_0000001233430205__b428371610207">FETCH ALL</strong> or <strong id="EN-US_TOPIC_0000001233430205__b3855344710207">FETCH BACKWARD ALL</strong> will always leave the cursor positioned after the last row or before the first row.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233430205__s5ef744a44b4b4afc8a24b4da7a14061b"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001233430205__u2d423adffa92488e8ebec76024fae21b"><li id="EN-US_TOPIC_0000001233430205__lc72eb677b479482183031d66ccde42db">If <strong id="EN-US_TOPIC_0000001233430205__b842352706134239">NO SCROLL</strong> is defined for the cursor, a backward fetch like <strong id="EN-US_TOPIC_0000001233430205__b842352706134513">FETCH BACKWARD</strong> is not allowed.</li><li id="EN-US_TOPIC_0000001233430205__ldb4ebde87c1846e6a8afd907de786f15">The forms <strong id="EN-US_TOPIC_0000001233430205__b4515561510207">NEXT</strong>, <strong id="EN-US_TOPIC_0000001233430205__b374735410207">PRIOR</strong>, <strong id="EN-US_TOPIC_0000001233430205__b3372618810207">FIRST</strong>, <strong id="EN-US_TOPIC_0000001233430205__b3510023810207">LAST</strong>, <strong id="EN-US_TOPIC_0000001233430205__b4746668910207">ABSOLUTE</strong>, and <strong id="EN-US_TOPIC_0000001233430205__b2454702310207">RELATIVE</strong> appropriately fetch a record after moving the cursor. If the cursor is already after the last row before being moved, an empty result is returned, and the cursor is left positioned before the first row (backward fetch) or after the last row (forward fetch) as appropriate.</li><li id="EN-US_TOPIC_0000001233430205__l2fbe8dbd273b4f33848d16697575a202">The forms using <strong id="EN-US_TOPIC_0000001233430205__b4215181210207">FORWARD</strong> and <strong id="EN-US_TOPIC_0000001233430205__b4382198910207">BACKWARD</strong> retrieve the indicated number of rows moving in the forward or backward direction, leaving the cursor positioned on the last-returned row (or after (backward fetch)/before (forward fetch) all rows, if the count exceeds the number of rows available).</li><li id="EN-US_TOPIC_0000001233430205__l67a9469172d14391b75f7fb92bdb19a4"><strong id="EN-US_TOPIC_0000001233430205__b5992026010207">RELATIVE 0</strong>, <strong id="EN-US_TOPIC_0000001233430205__b241143610207">FORWARD 0</strong>, and <strong id="EN-US_TOPIC_0000001233430205__b2170292410207">BACKWARD 0</strong> all request fetching the current row without moving the cursor, that is, re-fetching the most recently fetched row. This will succeed unless the cursor is positioned before the first row or after the last row, in which case, no row is returned.</li><li id="EN-US_TOPIC_0000001233430205__l6aa16feb30424f0d9e4d23a6f00dab47">If the cursor of <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0085031921_en-us_topic_0058966115_b842352706134852">FETCH</strong> involves a column-store table, backward fetches like <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0085031921_en-us_topic_0058966115_b842352706134921">BACKWARD</strong>, <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0085031921_en-us_topic_0058966115_b842352706134924">PRIOR</strong>, and <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0085031921_en-us_topic_0058966115_b842352706134938">FIRST</strong> are not supported.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233430205__s509ce26cd63945b1b832720f82941efb"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="EN-US_TOPIC_0000001233430205__saa624634631a48ec9c1b607fe3d14e9b">FETCH [ direction { FROM | IN } ] cursor_name;</pre>
<p id="EN-US_TOPIC_0000001233430205__a0a72636568a3406e87a1104cbf961a9c">The <strong id="EN-US_TOPIC_0000001233430205__b842352706134955">direction</strong> clause specifies optional parameters.</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430205__s9f01636bed2e470681d165213bfe50a7"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">NEXT</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">PRIOR</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">FIRST</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">LAST</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ABSOLUTE</span><span class="w"> </span><span class="k">count</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">RELATIVE</span><span class="w"> </span><span class="k">count</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">count</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ALL</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">FORWARD</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">FORWARD</span><span class="w"> </span><span class="k">count</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">FORWARD</span><span class="w"> </span><span class="k">ALL</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">BACKWARD</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">BACKWARD</span><span class="w"> </span><span class="k">count</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">BACKWARD</span><span class="w"> </span><span class="k">ALL</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001233430205__s680662240a104ac7a51873c7c888bdd1"><a name="EN-US_TOPIC_0000001233430205__s680662240a104ac7a51873c7c888bdd1"></a><a name="s680662240a104ac7a51873c7c888bdd1"></a><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001233430205__u1c03957a1d5746728d3a18e36a7e09ce"><li id="EN-US_TOPIC_0000001233430205__lbfa2352340674864b982f6c65bbeef37"><strong id="EN-US_TOPIC_0000001233430205__a0b8d410e4f4e4a1a8330d1b69d06f869">direction_clause</strong><p id="EN-US_TOPIC_0000001233430205__ac02127f0c5474bb4a13b4a1d442bf57f">Defines the fetch direction.</p>
<p id="EN-US_TOPIC_0000001233430205__a1782b952c43645c7829e626ddd1afab3">Valid value:</p>
<ul id="EN-US_TOPIC_0000001233430205__ueea8cf8c42db4520a5a79718b3d80c8e"><li id="EN-US_TOPIC_0000001233430205__lf857d60ccabc43329860f0668c64a599"><strong id="EN-US_TOPIC_0000001233430205__b842352706135038">NEXT</strong> (default value)<p id="EN-US_TOPIC_0000001233430205__aa28cbc7c76c64d3f9e48eea51b1141ff">Fetches the next row.</p>
</li><li id="EN-US_TOPIC_0000001233430205__lde95ea5f9a7e44f5851d4a32ca054bbb">PRIOR<p id="EN-US_TOPIC_0000001233430205__ad9298cca42eb40c0b9f0aaf301a2729a"><a name="EN-US_TOPIC_0000001233430205__lde95ea5f9a7e44f5851d4a32ca054bbb"></a><a name="lde95ea5f9a7e44f5851d4a32ca054bbb"></a>Fetches the prior row.</p>
</li><li id="EN-US_TOPIC_0000001233430205__l225bd986ee2640418a36e44c5438b8de">FIRST<p id="EN-US_TOPIC_0000001233430205__acd85f972dbae4d1d8d87ca306ededf67"><a name="EN-US_TOPIC_0000001233430205__l225bd986ee2640418a36e44c5438b8de"></a><a name="l225bd986ee2640418a36e44c5438b8de"></a>Fetches the first row of the query (same as <strong id="EN-US_TOPIC_0000001233430205__b3907216317531">ABSOLUTE 1</strong>).</p>
</li><li id="EN-US_TOPIC_0000001233430205__l6a8c958820c1456192f0f8334340b12b">LAST<p id="EN-US_TOPIC_0000001233430205__a0d882d7460e942929234ac215a2f073a"><a name="EN-US_TOPIC_0000001233430205__l6a8c958820c1456192f0f8334340b12b"></a><a name="l6a8c958820c1456192f0f8334340b12b"></a>Fetches the last row of the query (same as <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b2900179017531">ABSOLUTE -1</strong>).</p>
</li><li id="EN-US_TOPIC_0000001233430205__l27ef76b06be143fe867d5feb15a02d14">ABSOLUTE count<p id="EN-US_TOPIC_0000001233430205__ad688fb538f83413abbf51b0ef79f901c"><a name="EN-US_TOPIC_0000001233430205__l27ef76b06be143fe867d5feb15a02d14"></a><a name="l27ef76b06be143fe867d5feb15a02d14"></a>Fetches the (<strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b842352706135115">count</strong>)'th row of the query.</p>
<p id="EN-US_TOPIC_0000001233430205__a4f204a3720c447908461b983e71b21e2"><strong id="EN-US_TOPIC_0000001233430205__b3134052217531">ABSOLUTE</strong> fetches are not any faster than navigating to the desired row with a relative move: the underlying implementation must traverse all the intermediate rows anyway.</p>
<p id="EN-US_TOPIC_0000001233430205__af41a8a7ea828485da6c895307e3d328b"><strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b2605344817531_1">count</strong> is a possibly-signed integer constant:</p>
<ul id="EN-US_TOPIC_0000001233430205__u674e0ef54bfa491c94cd509a1ae0cb05"><li id="EN-US_TOPIC_0000001233430205__laed2da0d98604cbb81b712b6a1d601df">If <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b2647579717531">count</strong> is a positive integer, fetches the (count)'th row of the query, starting from the first row. If <strong id="EN-US_TOPIC_0000001233430205__b1121693054111444">count</strong> is less than the current cursor position, a <strong id="EN-US_TOPIC_0000001233430205__b842352706111529">rewind</strong> operation is required, which is currently not supported.</li><li id="EN-US_TOPIC_0000001233430205__l09ad9e30f76141e8a3aa1661df522a2d">If <strong id="EN-US_TOPIC_0000001233430205__b1364140740111630">count</strong> is a negative value or 0, a backward scanning is required, which is currently not supported.</li></ul>
</li><li id="EN-US_TOPIC_0000001233430205__lc272b3b9ccad40339642b51a082176f5">RELATIVE count<p id="EN-US_TOPIC_0000001233430205__ac09e2e6c57a5453da3870f3f5cbdf3ef"><a name="EN-US_TOPIC_0000001233430205__lc272b3b9ccad40339642b51a082176f5"></a><a name="lc272b3b9ccad40339642b51a082176f5"></a>Fetches the (count)'th succeeding row, or the abs(count)'th prior row if count is negative.</p>
<p id="EN-US_TOPIC_0000001233430205__addb7c70360a048d78f5f8bc8e8cdcc69"><strong id="EN-US_TOPIC_0000001233430205__b2605344817531">count</strong> is a possibly-signed integer constant:</p>
<ul id="EN-US_TOPIC_0000001233430205__u88730b14d3704c03b7261b96bdcffea9"><li id="EN-US_TOPIC_0000001233430205__l2fa9648eb5db482eb2ce09ded26e3186">If <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b3124469817531">count</strong> is a positive integer, fetches the (count)'th succeeding row.</li><li id="EN-US_TOPIC_0000001233430205__lcce98bc4f2734b0d99c19ab512fa5c34">If <strong id="EN-US_TOPIC_0000001233430205__b650123823">count</strong> is a negative value, a backward scanning is required, which is currently not supported.</li><li id="EN-US_TOPIC_0000001233430205__l05aa847808df44f781343013d9ab06cd"><strong id="EN-US_TOPIC_0000001233430205__b4693663817531">RELATIVE 0</strong> fetches the current row.</li></ul>
</li><li id="EN-US_TOPIC_0000001233430205__l395bb1f7030d4f3b92273422af9ee169">count<p id="EN-US_TOPIC_0000001233430205__afe09c5dd67c04571bf4b12426d7a01c6"><a name="EN-US_TOPIC_0000001233430205__l395bb1f7030d4f3b92273422af9ee169"></a><a name="l395bb1f7030d4f3b92273422af9ee169"></a>Fetches the next <strong id="EN-US_TOPIC_0000001233430205__b1366835117531">count</strong> rows (same as <strong id="EN-US_TOPIC_0000001233430205__b5590630217531">FORWARD count</strong>).</p>
</li><li id="EN-US_TOPIC_0000001233430205__l6a4d44979192415dafe2005ea6a94757">ALL<p id="EN-US_TOPIC_0000001233430205__abc8bd15b0b1f4c49909919cd10d60480"><a name="EN-US_TOPIC_0000001233430205__l6a4d44979192415dafe2005ea6a94757"></a><a name="l6a4d44979192415dafe2005ea6a94757"></a>Fetches all remaining rows (same as <strong id="EN-US_TOPIC_0000001233430205__b5986617817531">FORWARD ALL</strong>).</p>
</li><li id="EN-US_TOPIC_0000001233430205__l25b1947e24c04f30938377326c1075b0">FORWARD<p id="EN-US_TOPIC_0000001233430205__af5b822d6f89743dc84df2fd2ec5717fc"><a name="EN-US_TOPIC_0000001233430205__l25b1947e24c04f30938377326c1075b0"></a><a name="l25b1947e24c04f30938377326c1075b0"></a>Fetches the next row (same as <strong id="EN-US_TOPIC_0000001233430205__b5339893817531">NEXT</strong>).</p>
</li><li id="EN-US_TOPIC_0000001233430205__l8afa69c4afc748cb962912866f926453">FORWARD count<p id="EN-US_TOPIC_0000001233430205__a81611cc402c74f9a8ee936d8a4b2b83e"><a name="EN-US_TOPIC_0000001233430205__l8afa69c4afc748cb962912866f926453"></a><a name="l8afa69c4afc748cb962912866f926453"></a>Fetches the next <strong id="EN-US_TOPIC_0000001233430205__b84235270611314">count</strong> rows (same as <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b5453500717531">RELATIVE count</strong>). <strong id="EN-US_TOPIC_0000001233430205__en-us_topic_0058966115_b2105301517531">FORWARD 0</strong> re-fetches the current row.</p>
</li><li id="EN-US_TOPIC_0000001233430205__l970cf23469f84cbab6e1d4fb549e6841">FORWARD ALL<p id="EN-US_TOPIC_0000001233430205__aa164bd0849ae4605ae9a3e9589b00cca"><a name="EN-US_TOPIC_0000001233430205__l970cf23469f84cbab6e1d4fb549e6841"></a><a name="l970cf23469f84cbab6e1d4fb549e6841"></a>Fetches all remaining rows.</p>
</li><li id="EN-US_TOPIC_0000001233430205__l6919f35dccdf4b4ab1f312ce7f638b88">BACKWARD<p id="EN-US_TOPIC_0000001233430205__ae3cafaa9d8a14bce885adad7f143dc82"><a name="EN-US_TOPIC_0000001233430205__l6919f35dccdf4b4ab1f312ce7f638b88"></a><a name="l6919f35dccdf4b4ab1f312ce7f638b88"></a>Fetches the prior row (same as <strong id="EN-US_TOPIC_0000001233430205__b6246298917531">PRIOR</strong>).</p>
</li><li id="EN-US_TOPIC_0000001233430205__ld00abd77698f4b31926f77453a3c77b8">BACKWARD count<p id="EN-US_TOPIC_0000001233430205__a0e031001343a4e32968119a4c4af15f9"><a name="EN-US_TOPIC_0000001233430205__ld00abd77698f4b31926f77453a3c77b8"></a><a name="ld00abd77698f4b31926f77453a3c77b8"></a>Fetches the prior <strong id="EN-US_TOPIC_0000001233430205__b842352706113127">count</strong> rows (scanning backwards).</p>
<p id="EN-US_TOPIC_0000001233430205__aab3054b83d1a4c69883a9c36ae6f51cd"><strong id="EN-US_TOPIC_0000001233430205__b981604619">count</strong> is a possibly-signed integer constant:</p>
<ul id="EN-US_TOPIC_0000001233430205__uc2bfa1fa3cfe498aaeb4cd14a0f405c7"><li id="EN-US_TOPIC_0000001233430205__l77b0bc28a4b74e71afa2ac2b378c3b09">If <strong id="EN-US_TOPIC_0000001233430205__b3936152217531">count</strong> is a positive integer, fetches the (count)'th prior row.</li><li id="EN-US_TOPIC_0000001233430205__l1b7da7840e9043849a505f6d86215827">If <strong id="EN-US_TOPIC_0000001233430205__b1604343617531">count</strong> is a negative integer, fetches the abs(count)'th succeeding row.</li><li id="EN-US_TOPIC_0000001233430205__l65cbdd95644b47f18b6e765ddd85a2a1"><strong id="EN-US_TOPIC_0000001233430205__b3428659917531">BACKWARD 0</strong> re-fetches the current row.</li></ul>
</li><li id="EN-US_TOPIC_0000001233430205__l6ad837248748463fb8280b01016119f4">BACKWARD ALL<p id="EN-US_TOPIC_0000001233430205__a5f91c6e1163040cba5f47f94ed184139"><a name="EN-US_TOPIC_0000001233430205__l6ad837248748463fb8280b01016119f4"></a><a name="l6ad837248748463fb8280b01016119f4"></a>Fetches all prior rows (scanning backwards).</p>
</li></ul>
</li><li id="EN-US_TOPIC_0000001233430205__l3899d9cfd6af4731b2b940dce5900545"><strong id="EN-US_TOPIC_0000001233430205__a34941515504a4e729d699f2a82954aa2">{ FROM | IN } cursor_name</strong><p id="EN-US_TOPIC_0000001233430205__a92de5c6e69314f2c9a0b2b710cc3a174">Specifies the cursor name using the keyword <strong id="EN-US_TOPIC_0000001233430205__b2585007017531">FROM</strong> or <strong id="EN-US_TOPIC_0000001233430205__b3132404317531">IN</strong>.</p>
<p id="EN-US_TOPIC_0000001233430205__ae14445dd3ddc4794b2d930f8d76b1f1b">Value range: an existing cursor name.</p>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233430205__sa2a56d1c1dbf48e3a251f3e518813217"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001233430205__p163870521469">Example 1: Run the <strong id="EN-US_TOPIC_0000001233430205__b18725028233528">SELECT</strong> statement to read a table using a cursor.</p>
<p id="EN-US_TOPIC_0000001233430205__p1738710521164">Set up the <strong id="EN-US_TOPIC_0000001233430205__b10346194818399">cursor1 </strong>cursor:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430205__screen64371356991"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CURSOR</span><span class="w"> </span><span class="n">cursor1</span><span class="w"> </span><span class="k">FOR</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">customer_address</span><span class="w"> </span><span class="k">ORDER</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001233430205__p038795215610">Fetch the first three rows from <strong id="EN-US_TOPIC_0000001233430205__b97737576396">cursor1</strong>:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430205__screen114702010991"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">FETCH</span><span class="w"> </span><span class="k">FORWARD</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">cursor1</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001233430205__p838665213614">Example 2: Use a cursor to read the content in the <strong id="EN-US_TOPIC_0000001233430205__b121529336433528">VALUES</strong> clause.</p>
<p id="EN-US_TOPIC_0000001233430205__p9386185219619">Set up the cursor <strong id="EN-US_TOPIC_0000001233430205__b1663711482408">cursor2</strong>:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430205__screen266364513819"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CURSOR</span><span class="w"> </span><span class="n">cursor2</span><span class="w"> </span><span class="k">FOR</span><span class="w"> </span><span class="k">VALUES</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">),(</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span><span class="w"> </span><span class="k">ORDER</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001233430205__p103861852165">Fetch the first two rows from <strong id="EN-US_TOPIC_0000001233430205__b168936511403">cursor2</strong>:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430205__screen1843916501285"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">FETCH</span><span class="w"> </span><span class="k">FORWARD</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">cursor2</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001233430205__s68c1873d29fa41ee812a1ac46b9b1765"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001233430205__ad1057b70ff114a06950196a6cd595007"><a href="dws_06_0152.html">CLOSE</a>, <a href="dws_06_0217.html">MOVE</a></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0118.html">DDL Syntax</a></div>
</div>
</div>