CLOSE statement

Use the CLOSE statement when you no longer need to refer to the set of rows associated with a Select cursor or with a Function cursor. With ESQL/C, this statement can also flush and close an Insert cursor. Use this statement with or SPL.

Syntax

(1)
Notes:
  • 1 HCL OneDB™ extension
  • 2 ESQL/C only
Element Description Restrictions Syntax
cursor_id Name of cursor to be closed Must have been declared Identifier
cursor_id_var Host variable that contains the value of cursor_id Must be of a character data type Must conform to language-specific rules for names.

Usage

Closing a cursor makes the cursor unusable in any statements except OPEN or FREE and releases resources that the database server had allocated to the cursor.

In a database that is not ANSI-compliant, you can close a cursor that has not been opened or that has already been closed. No action is taken in these cases.

In an ANSI-compliant database, the database server returns an error if you close a cursor that was not open.

Examples

The following statement closes the cursor, democursor.
EXEC SQL close democursor;
The following is ESQL/C Source code example from demo1.ec:
#include <stdio.h>

EXEC SQL define FNAME_LEN       15;
EXEC SQL define LNAME_LEN       15;

main()
{

EXEC SQL BEGIN DECLARE SECTION;
    char fname[ FNAME_LEN + 1 ];
    char lname[ LNAME_LEN + 1 ];
EXEC SQL END DECLARE SECTION;

    printf( "DEMO1 Sample ESQL Program running.\n\n");

    EXEC SQL WHENEVER ERROR STOP;

    EXEC SQL connect to 'stores7';

    EXEC SQL declare democursor cursor for
        select fname, lname
           into :fname, :lname
           from customer
           where lname < "C";

    EXEC SQL open democursor;
    for (;;)
        {
        EXEC SQL fetch democursor;
        if (strncmp(SQLSTATE, "00", 2) != 0)
            break;
        printf("%s %s\n",fname, lname);
        }
    if (strncmp(SQLSTATE, "02", 2) != 0)
        printf("SQLSTATE after fetch is %s\n", SQLSTATE);

    EXEC SQL close democursor;
    EXEC SQL free democursor;
    EXEC SQL create routine from 'del_ord.sql';
    EXEC SQL disconnect current;
    printf("\nDEMO1 Sample Program over.\n\n");
   exit(0);
}