CLOSE 子句

当您不再需要引用 Select 或 Function 游标检索的行时,使用 CLOSE 子句。在 ESQL/C 中,该语句还可以刷新并关闭 Insert 游标。可在 GBase 8s ESQL/C 或 SPL 中使用此语句。

语法

元素 描述 限制 语法
cursor_id 要关闭的游标的名称 必须已声明 标识符
cursor_id_var 包含 cursor_id 的值的主变量 必须是字符数据类型 必须符合特定于语言的名称规则

用法

关闭游标使得游标对于除 OPEN 或 FREE 之外的任何语句无用,并释放数据库服务器已经分配到游标的资源。

在不兼容 ANSI 的数据库中,您可以关闭尚未打开的游标或已经关闭的游标。在这些情况下没有采取任何操作。

在兼容 ANSI 的数据库中,如果您关闭尚未打开的游标,那么数据库服务器返回错误。

示例

以下示例关闭了游标 democursor
EXEC SQL close democursor;
以下是来自 demo1.ec 的 ESQL/C Source 代码示例:
#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);
} 

1 GBase 8s 扩展
2 仅限于 ESQL/C