Deallocates a cursor for a static SQL statement or for a dynamic SQL statement.
exec sql [at connection_name] deallocate cursor cursor_name end-exec
The name of the cursor to be deallocated. The cursor_name must be a character string enclosed in double quotation marks or in no quotation marks—for example "my_cursor" or my_cursor. It cannot be a host variable.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 TITLE-ID PIC X(7).
01 BOOK-NAME PIC X(80).
01 TTYPE PIC X(12).
01 TITLE-INDIC S9(9).
01 TYPE-INDIC S9(9).
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL DECLARE titlelist CURSOR FOR
SELECT type, title_id, title FROM titles
order by type END-EXEC.
EXEC SQL OPEN titlelist END-EXEC.
PERFORM FETCH-PARA UNTIL SQLCODE = 100.
EXEC SQL CLOSE titlelist END-EXEC.
EXEC SQL DEALLOCATE CURSOR titlelist END-EXEC.
...
FETCH-PARA.
EXEC SQL FETCH titlelist INTO
:TTYPE :TYPE-INDIC,
:TITLE-ID,
:BOOK-NAME :TITLE-INDIC END-EXEC.
IF TYPE-INDIC <> -1
DISPLAY "TYPE : ", TTYPE
ELSE
DISPLAY "TYPE : UNDECIDED"
END-IF.
DISPLAY "TITLE ID : ",TITLE-ID.
IF TITLE-INDIC <> -1
DISPLAY "TITLE : ", BOOK-NAME
ELSE
DISPLAY "TITLE : Null value"
END-IF.
END-FETCH-PARA.
Deallocating a cursor releases all resources allocated to the cursor. In particular, deallocate cursor drops the Client-Library command handle and CS_COMMAND structure associated with the cursor.
A static cursor can be deallocated at any time after it is opened. A dynamic cursor can be deallocated at any time after it is declared.
If cursor_name is open, deallocate cursor closes it and then deallocates it.
You cannot reference a deallocated cursor, nor can you reopen it. If you try, an error occurs.
You can declare a new cursor having the same name as that of a deallocated cursor. Opening a cursor with the same name as a deallocated cursor is not the same as reopening the deallocated cursor. Other than the name, the new cursor shares nothing with the deallocated cursor.
Declaring a new cursor with the same name as that of a deallocated cursor can cause the precompiler to generate a warning message.
The deallocate cursor statement is a Sybase extension; it is not defined in the SQL standard.
If you are using persistent binding in your Embedded
SQL program, use the deallocate cursor statement
carefully. Needlessly deallocating cursors can negate the advantage
of persistent binding.
close cursor, declare cursor, open (static cursor)