declare cursor (dynamic)

Description

Declares a cursor for processing multiple rows returned by a prepared dynamic select statement.

Syntax

exec sql [at connection_name] 
 declare cursor_name 
 cursor for prepped_statement_name; 

Parameters

cursor_name

The cursor’s name, used to reference the cursor in open, fetch, and close statements. A cursor’s name must be unique on each connection and must have no more than 255 characters.

prepped_statement_name

The name (specified in a previous prepare statement) that represents the select statement to be executed.

Examples

Example 1

exec sql begin declare section; 
CS_CHAR        sqlstmt[100]; 
exec sql end declare section; 
strcpy(sqlstmt, “select * from publishers”);
exec sql prepare make_work from :sqlstmt;
exec sql declare make_work_cursor cursor for
     make_work;
exec sql deallocate prepare make_work;

Usage

See also

close, connect, fetch, open, prepare