CLOSE

The CLOSE statement closes a cursor. If a result table was created when the cursor was opened, that table is destroyed.

Invocation

This statement can only be embedded in an application program. It is an executable statement that cannot be dynamically prepared. It must not be specified in Java™.

Authorization

None required. See DECLARE CURSOR for the authorization required to use a cursor.

Syntax

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram>>-CLOSE--cursor-name------------------------------------------><
 

Description

cursor-name
Identifies the cursor to be closed. The cursor-name must identify a declared cursor as explained in the DECLARE CURSOR statement. When the CLOSE statement is executed, the cursor must be in the open state.

Notes

Implicit cursor close: All cursors in a program are in the closed state when:

Note:
The DB2 UDB for iSeries database manager will open files in order to implement queries. The closing of the files can be separate from the SQL CLOSE statement. For more information, see the SQL Programming book.

Close cursors for performance: Explicitly closing cursors as soon as possible can improve performance.

Procedure considerations: Special rules apply to cursors within procedures that have not been closed before returning to the calling program. For more information, see CALL.

Example

In a COBOL program, use the cursor C1 to fetch the values from the first four columns of the EMPPROJACT table a row at a time and put them in the following host variables:

Finally, close the cursor.

   EXEC SQL  BEGIN DECLARE SECTION  END-EXEC.
     77  EMP              PIC X(6).
     77  PRJ              PIC X(6).
     77  ACT              PIC S9(4) BINARY.
     77  TIM              PIC S9(3)V9(2) PACKED-DECIMAL.
   EXEC SQL  END DECLARE SECTION  END-EXEC.
   .
   .
   .

   EXEC SQL  DECLARE C1 CURSOR FOR
               SELECT EMPNO, PROJNO, ACTNO, EMPTIME
                 FROM EMPPROJACT                        END-EXEC.

   EXEC SQL  OPEN C1  END-EXEC.

   EXEC SQL  FETCH C1 INTO :EMP, :PRJ, :ACT, :TIM  END-EXEC.

   IF SQLSTATE = '02000'
     PERFORM DATA-NOT-FOUND
   ELSE
     PERFORM GET-REST-OF-ACTIVITY UNTIL SQLSTATE IS NOT EQUAL TO '00000'.

   EXEC SQL  CLOSE C1  END-EXEC.

   GET-REST-OF-ACTIVITY
   EXEC SQL  FETCH C1 INTO :EMP, :PRJ, :ACT, :TIM  END-EXEC.
   .
   .
   .


[ Top of Page | Previous Page | Next Page | Contents | Index ]