<simplelist type="inline">
<member><xref linkend="ecpg-sql-allocate-descriptor"/></member>
<member><xref linkend="ecpg-sql-get-descriptor"/></member>
<member><xref linkend="ecpg-sql-set-descriptor"/></member>
</simplelist>
</refsect1>
</refentry>
<refentry id="ecpg-sql-declare">
<refnamediv>
<refname>DECLARE</refname>
<refpurpose>define a cursor</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
DECLARE <replaceable class="parameter">cursor_name</replaceable> [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ] CURSOR [ { WITH | WITHOUT } HOLD ] FOR <replaceable class="parameter">prepared_name</replaceable>
DECLARE <replaceable class="parameter">cursor_name</replaceable> [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ] CURSOR [ { WITH | WITHOUT } HOLD ] FOR <replaceable class="parameter">query</replaceable>
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>DECLARE</command> declares a cursor for iterating over
the result set of a prepared statement. This command has
slightly different semantics from the direct SQL
command <command>DECLARE</command>: Whereas the latter executes a
query and prepares the result set for retrieval, this embedded
SQL command merely declares a name as a <quote>loop
variable</quote> for iterating over the result set of a query;
the actual execution happens when the cursor is opened with
the <command>OPEN</command> command.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry id="ecpg-sql-declare-cursor-name">
<term><replaceable class="parameter">cursor_name</replaceable></term>
<listitem>
<para>
A cursor name, case sensitive. This can be an SQL identifier
or a host variable.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sql-declare-prepared-name">
<term><replaceable class="parameter">prepared_name</replaceable></term>
<listitem>
<para>
The name of a prepared query, either as an SQL identifier or a
host variable.
</para>
</listitem>
</varlistentry>
<varlistentry id="ecpg-sql-declare-query">
<term><replaceable class="parameter">query</replaceable></term>
<listitem>
<para>
A <xref linkend="sql-select"/> or
<xref linkend="sql-values"/> command which will provide the
rows to be returned by the cursor.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
For the meaning of the cursor options,
see <xref linkend="sql-declare"/>.
</para>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
Examples declaring a cursor for a query:
<programlisting>
EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table;
EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;
EXEC SQL DECLARE cur1 CURSOR FOR SELECT version();
</programlisting>
</para>
<para>
An example declaring a cursor for a prepared statement:
<programlisting>
EXEC SQL PREPARE stmt1 AS SELECT version();
EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
</programlisting>
</para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
<command>DECLARE</command> is specified in the SQL standard.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="ecpg-sql-open"/></member>
<member><xref linkend="sql-close"/></member>
<member><xref linkend="sql-declare"/></member>
</simplelist>
</refsect1>
</refentry>
<refentry id="ecpg-sql-declare-statement">
<refnamediv>
<refname>DECLARE STATEMENT</refname>
<refpurpose>declare SQL statement identifier</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
EXEC SQL [ AT <replaceable class="parameter">connection_name</replaceable> ] DECLARE