<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="fetch">
      </a>
      15.6.6.3 Cursor FETCH Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045176132288">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa90446747"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">FETCH</span> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token keyword">NEXT</span><span class="token punctuation">]</span> <span class="token keyword">FROM</span><span class="token punctuation">]</span> <span class="token keyword"><em class="replaceable">cursor_name</em></span> <span class="token keyword">INTO</span> <em class="replaceable">var_name</em> <span class="token punctuation">[</span><span class="token punctuation">,</span> <em class="replaceable">var_name</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
  </div>
  <p>
   This statement fetches the next row for the
   <a class="link" href="select.html" title="15.2.13 SELECT Statement">
    <code class="literal">
     SELECT
    </code>
   </a>
   statement associated with
        the specified cursor (which must be open), and advances the
        cursor pointer. If a row exists, the fetched columns are stored
        in the named variables. The number of columns retrieved by the
   <a class="link" href="select.html" title="15.2.13 SELECT Statement">
    <code class="literal">
     SELECT
    </code>
   </a>
   statement must match the
        number of output variables specified in the
   <a class="link" href="fetch.html" title="15.6.6.3 Cursor FETCH Statement">
    <code class="literal">
     FETCH
    </code>
   </a>
   statement.
  </p>
  <p>
   If no more rows are available, a No Data condition occurs with
        SQLSTATE value
   <code class="literal">
    '02000'
   </code>
   . To detect this
        condition, you can set up a handler for it (or for a
   <code class="literal">
    NOT FOUND
   </code>
   condition). For an example, see
   <a class="xref" href="cursors.html" title="15.6.6 Cursors">
    Section 15.6.6, “Cursors”
   </a>
   .
  </p>
  <p>
   Be aware that another operation, such as a
   <code class="literal">
    SELECT
   </code>
   or another
   <code class="literal">
    FETCH
   </code>
   ,
        may also cause the handler to execute by raising the same
        condition. If it is necessary to distinguish which operation
        raised the condition, place the operation within its own
   <a class="link" href="begin-end.html" title="15.6.1 BEGIN ... END Compound Statement">
    <code class="literal">
     BEGIN ...
        END
    </code>
   </a>
   block so that it can be associated with its own
        handler.
  </p>
 </div>
 <br/>
</div>
