Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
ecpg-sql-declare.html43 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!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"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>DECLARE</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="ecpg-sql-deallocate-descriptor.html" title="DEALLOCATE DESCRIPTOR" /><link rel="next" href="ecpg-sql-declare-statement.html" title="DECLARE STATEMENT" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">DECLARE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg-sql-deallocate-descriptor.html" title="DEALLOCATE DESCRIPTOR">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ecpg-sql-commands.html" title="36.14. Embedded SQL Commands">Up</a></td><th width="60%" align="center">36.14. Embedded SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ecpg-sql-declare-statement.html" title="DECLARE STATEMENT">Next</a></td></tr></table><hr /></div><div class="refentry" id="ECPG-SQL-DECLARE"><div class="titlepage"></div><div class="refnamediv"><h2>DECLARE</h2><p>DECLARE — define a cursor</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">3DECLARE <em class="replaceable"><code>cursor_name</code></em> [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ] CURSOR [ { WITH | WITHOUT } HOLD ] FOR <em class="replaceable"><code>prepared_name</code></em>4DECLARE <em class="replaceable"><code>cursor_name</code></em> [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ] CURSOR [ { WITH | WITHOUT } HOLD ] FOR <em class="replaceable"><code>query</code></em>5</pre></div><div class="refsect1" id="id-1.7.5.20.6.3"><h2>Description</h2><p>6     <code class="command">DECLARE</code> declares a cursor for iterating over7     the result set of a prepared statement.  This command has8     slightly different semantics from the direct SQL9     command <code class="command">DECLARE</code>: Whereas the latter executes a10     query and prepares the result set for retrieval, this embedded11     SQL command merely declares a name as a <span class="quote">“<span class="quote">loop12     variable</span>”</span> for iterating over the result set of a query;13     the actual execution happens when the cursor is opened with14     the <code class="command">OPEN</code> command.15    </p></div><div class="refsect1" id="id-1.7.5.20.6.4"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt id="ECPG-SQL-DECLARE-CURSOR-NAME"><span class="term"><em class="replaceable"><code>cursor_name</code></em></span> <a href="#ECPG-SQL-DECLARE-CURSOR-NAME" class="id_link">#</a></dt><dd><p>16        A cursor name, case sensitive.  This can be an SQL identifier17        or a host variable.18       </p></dd><dt id="ECPG-SQL-DECLARE-PREPARED-NAME"><span class="term"><em class="replaceable"><code>prepared_name</code></em></span> <a href="#ECPG-SQL-DECLARE-PREPARED-NAME" class="id_link">#</a></dt><dd><p>19        The name of a prepared query, either as an SQL identifier or a20        host variable.21       </p></dd><dt id="ECPG-SQL-DECLARE-QUERY"><span class="term"><em class="replaceable"><code>query</code></em></span> <a href="#ECPG-SQL-DECLARE-QUERY" class="id_link">#</a></dt><dd><p>22        A <a class="xref" href="sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a> or23        <a class="xref" href="sql-values.html" title="VALUES"><span class="refentrytitle">VALUES</span></a> command which will provide the24        rows to be returned by the cursor.25       </p></dd></dl></div><p>26     For the meaning of the cursor options,27     see <a class="xref" href="sql-declare.html" title="DECLARE"><span class="refentrytitle">DECLARE</span></a>.28    </p></div><div class="refsect1" id="id-1.7.5.20.6.5"><h2>Examples</h2><p>29     Examples declaring a cursor for a query:30</p><pre class="programlisting">31EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table;32EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;33EXEC SQL DECLARE cur1 CURSOR FOR SELECT version();34</pre><p>35    </p><p>36     An example declaring a cursor for a prepared statement:37</p><pre class="programlisting">38EXEC SQL PREPARE stmt1 AS SELECT version();39EXEC SQL DECLARE cur1 CURSOR FOR stmt1;40</pre><p>41    </p></div><div class="refsect1" id="id-1.7.5.20.6.6"><h2>Compatibility</h2><p>42     <code class="command">DECLARE</code> is specified in the SQL standard.43    </p></div><div class="refsect1" id="id-1.7.5.20.6.7"><h2>See Also</h2><span class="simplelist"><a class="xref" href="ecpg-sql-open.html" title="OPEN">OPEN</a>, <a class="xref" href="sql-close.html" title="CLOSE"><span class="refentrytitle">CLOSE</span></a>, <a class="xref" href="sql-declare.html" title="DECLARE"><span class="refentrytitle">DECLARE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg-sql-deallocate-descriptor.html" title="DEALLOCATE DESCRIPTOR">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ecpg-sql-commands.html" title="36.14. Embedded SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ecpg-sql-declare-statement.html" title="DECLARE STATEMENT">Next</a></td></tr><tr><td width="40%" align="left" valign="top">DEALLOCATE DESCRIPTOR </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> DECLARE STATEMENT</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai