SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Static SQL Cursors
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
6-2
Steps for Using a Static SQL Cursor
Steps for Using a Static SQL Cursor 
Figure 6-1 shows the steps presented within the complete C program. These steps are 
executed in the sample program Example A-1 on page A-1.
Note. Using a cursor can sometimes degrade performance. A cursor requires OPEN, FETCH, 
and CLOSE statements, which increase the number of messages between the HP NonStop 
Distribution Service (DS) and the HP NonStop Data Access Manager (DAM). Consider not 
using a cursor if a single-row retrieval is sufficient.
Figure 6-1. Using a Static SQL Cursor in a C Program
...
EXEC SQL BEGIN DECLARE SECTION;
int hostvar;
...
EXEC SQL END DECLARE SECTION; 
...
EXEC SQL DECLARE sql_cursor CURSOR FOR 
 SELECT column_1, column_2, ..., column_n 
 FROM catalog.schema.table 
 WHERE column_1 = :hostvar; 
...
void find_row(void)
{ 
...
hostvar = initial_value; 
...
EXEC SQL OPEN sql_cursor; 
 ...
EXEC SQL FETCH sql_cursor 
 INTO :hostvar_1, :hostvar_2, ..., :hostvar_n;
...
... /* Process values in the host variable(s). */ 
...
... /* If last row has not been processed, */ 
 /* branch back to fetch another row. */ 
...
EXEC SQL CLOSE sql_cursor;
...
} /* end find_row
...
C
1
2
3
4
5
6
7
8










