deallocate cursor

Description

Deallocates a cursor for a static SQL statement or for a dynamic SQL statement.

Syntax

exec sql [at connection_name] deallocate cursor cursor_name end-exec

Parameters

cursor_name

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.

Examples

Example 1

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.

Usage

NoteIf 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.

See also

close cursor, declare cursor, open (static cursor)