Opens a previously declared static cursor. This statement can be used to open any static cursor, including one for a stored procedure.
exec sql [at connection_name] open cursor_name [row_count = size];
The name of the cursor to be opened.
The number of rows moved in a network roundtrip, not the number fetched into the host variable.
The number of rows that are moved at the same time from Adaptive Server to the client. The client buffers the rows until they are fetched by the application. This parameter allows you to tune network efficiency.
exec sql begin declare section;
char b_titleid[tidsize+1];
char b_title[65];
char b_type[typesize+1];
exec sql end declare section;
long sqlcode;
char response[10];
...
exec sql declare titlelist cursor for
select title_id, substring(title,1,64)
from titles where type like :b_type;
strcpy(b_type, "business");
exec sql open titlelist;
for (;;)
exec sql fetch titlelist into :b_titleid,
:b_title;
if (sqlcode == 100)
break;
printf(" %-8s %s\n", b_titleid, b_title);
printf("update/delete? ");
gets(response);
if (!strncasecmp(response,"u",1))
{
printf("enter the new titleid\n>");
gets(b_titleid);
exec sql update titles
set title_id = :b_titleid
where current of titlelist;
}
else if (!strncasecmp(response,"d",1))
{
exec sql delete from titles
where current of titlelist;
}
}
exec sql close titlelist;
open executes the select statement given by the declare cursor statement and prepares results for the fetch statement.
You can have an unlimited number of open cursors.
A static cursor must be opened only in the file where the cursor is declared. The cursor can be closed in any file.
The values of host variables embedded in the declare cursor statement are taken at open time.
When specifying cursor_name, you can use the name of a deallocated static cursor. If you do, the precompiler declares and opens a new cursor having the same name as that of the deallocated cursor. Thus, the precompiler does not reopen the deallocated cursor but instead creates a new one. The results sets for the two cursors can differ.