Using a Select Procedure with Cursors
Go Up to Using Select Procedures
A select procedure can also be used in a cursor declaration. For example, the following code declares a cursor named PROJECTS, using the GET_EMP_PROJ procedure in place of a table:
EXEC SQL DECLARE PROJECTS CURSOR FOR SELECT PROJ_ID FROM GET_EMP_PROJ (:emp_no) ORDER BY PROJ_ID;
The following application C code with embedded SQL then uses the PROJECTS cursor to print project numbers to standard output:
EXEC SQL
OPEN PROJECTS
/* Print employee projects. */
while (SQLCODE == 0)
{
EXEC SQL
FETCH PROJECTS INTO :proj_id :nullind;
if (SQLCODE == 100)
break;
if (nullind == 0)
printf("\t%s\n", proj_id);
}