Declares a cursor for a stored procedure.
exec sql declare cursor_name cursor for execute procedure_name ([[@param_name =]:host_var] [,[@param_name =]:host_var]…)
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 128 characters.
The name of the stored procedure to be executed.
The name of a parameter in the stored procedure.
The name of a host variable to be passed as a parameter value.
main()
{
exec sql begin declare section;
CS_CHAR b_titleid[7];
CS_CHAR b_title[65];
CS_CHAR b_type[13];
exec sql end declare section;
long SQLCODE;
exec sql connect “sa”;
exec sql use pubs2;
exec sql
create procedure p_titles
(@p_type varchar(30)) as
select title_id, substring(title,1,64)
from titles
where type like @p_type;
exec sql declare titlelist cursor for
execute p_titles (: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);
}
exec sql close titlelist;
exec sql disconnect all;
}
procedure_name must consist of only one select statement.
It is not possible to retrieve output parameter values from a stored procedure executed using a cursor.
It is not possible to retrieve the return status value of a stored procedure executed using a cursor.
close, deallocate cursor, declare cursor (static), declare cursor (dynamic), fetch, open, update