The CLOSE statement ends row-at-a-time data retrieval initiated by the OPEN statement for a specified cursor, and closes the cursor connection.
CLOSE cursor_name
The CLOSE statement discards unprocessed rows and frees any locks held by the cursor. The cursor must be declared and opened before it can be closed. All open cursors are closed automatically at the end of the program.
EXEC SQL DECLARE C1 CURSOR FOR
SELECT id, name, dept, job, years, salary, comm FROM staff;
EXEC SQL OPEN c1;
while (SQLCODE == 0)
{
/* SQLCODE will be zero if data is successfully fetched */
EXEC SQL
FETCH c1 INTO :id, :name, :dept, :job, :years, :salary, :comm;
if (SQLCODE == 0)
printf("%4d %12s %10d %10s %2d %8d %8d",
id, name, dept, job, years, salary, comm);
}
EXEC SQL CLOSE c1;
DECLARE CURSOR | OPEN |
FETCH | SET CURSOR_CLOSE_ON_COMMIT |