deallocate cursor

Description

Deallocates a cursor for a static SQL statement or for a dynamic SQL statement.

Syntax

exec sql [at connection_name] deallocate cursor cursor_name; 

Parameters

cursor_name

The name of the cursor to be deallocated. The cursor_name must be a character string enclosed in double quotation marks or in no quotation marks—for example “my_cursor" or my_cursor. It cannot be a host variable.

Examples

Example 1

exec sql include sqlca;
main()
{
exec sql begin declare section;
     CS_CHAR title[80];
     CS_SMALLINT i_title;
exec sql end declare section;
exec sql whenever sqlerror call error_handler();
exec sql whenever sqlwarning call error_handler();
exec sql whenever not found continue;
exec sql connect “sa”;
exec sql use pubs2;
exec sql declare title_list cursor for select title from titles;

exec sql open title_list;
for (;;)
{
     exec sql fetch title_list into :title :i_title;
     if (sqlca.sqlcode == 100)  break;

     if (i_title == -1)  printf(“Title is NULL.\n”);

     printf(“Title: %s\n”, title);
}
exec sql close title_list;
exec sql deallocate cursor title_list;
exec sql disconnect all;
exit(0);
}
error_handler()
{
printf(“%d\n%s\n”,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
exec sql deallocate cursor title_list;
exec sql disconnect all;
exit(-1);
}

Usage

NoteIf you are using persistent binding in your Embedded SQL program, use the deallocate cursor statement carefully. Needlessly deallocating cursors can negate the advantage of persistent binding.

See also

close cursor, declare cursor, open (static cursor)