SQL$HELP72.HLB  —  CLOSE
    Closes an open cursor.

1  –  Environment

    You can use the CLOSE statement:

    o  In interactive SQL

    o  Embedded in host language programs to be precompiled

    o  As part of a procedure in an SQL module

2  –  Format

  (B)0CLOSE qwq> <cursor-name> qqqqqqqqqqqwq>  
         mq> <cursor-name-parameter> qj    

3  –  Arguments

3.1  –  cursor-name

    The name of the cursor you want to close.

3.2  –  cursor-name-parameter

    Use a parameter if the cursor referred to by the cursor name
    was declared at run time with an extended dynamic DECLARE CURSOR
    statement. Specify the same cursor name parameter used in the
    dynamic DECLARE CURSOR statement.

    You can use a parameter to refer to the cursor name only when the
    CLOSE statement is accessing a dynamic cursor.

4  –  Examples

    Example 1: Closing a cursor declared in a PL/I program

    This program fragment uses embedded DECLARE CURSOR, OPEN, and
    FETCH statements to retrieve and print the name and department of
    managers. The CLOSE statement closes the cursor after the FETCH
    statement fails to find any more rows in the result table (when
    SQLCODE is set to 100).

    /* Declare the cursor: */
    EXEC SQL DECLARE MANAGER CURSOR FOR
            SELECT E.FIRST_NAME, E.LAST_NAME, D.DEPARTMENT_NAME
                    FROM EMPLOYEES E, DEPARTMENTS D
                    WHERE E.EMPLOYEE_ID = D.MANAGER_ID ;

    /* Open the cursor: */
    EXEC SQL OPEN MANAGER;

    /* Start a loop to process the rows of the cursor: */
    DO WHILE (SQLCODE = 0);
            /* Retrieve the rows of the cursor
            and put the value in host language variables: */
            EXEC SQL FETCH MANAGER INTO :FNAME, :LNAME, :DNAME;
            /* Print the values in the variables: */
                            .
                            .
                            .
    END;

    /* Close the cursor: */
    EXEC SQL CLOSE MANAGER;
Close Help