CLOSE

Embedded SQL for C and SQL Server

Embedded SQL for C and SQL Server

CLOSE

The CLOSE statement ends row-at-a-time data retrieval initiated by the OPEN statement for a specified cursor, and closes the cursor connection.

Syntax

CLOSE cursor_name

Arguments

cursor_name

Is a previously declared and opened cursor. Cursor names can have as many as 30 characters, and can include alphanumeric characters and any symbols that are legal in file names. Hyphens (-) are not permitted. The first character of a cursor name must be a letter.

Remarks

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.

Examples
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;

See Also

DECLARE CURSOR

OPEN

FETCH

SET CURSOR_CLOSE_ON_COMMIT