SQL$HELP_OLD72.HLB  —  CLOSE  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