Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 有人能解释一下如何在SQLServer中用示例代码手动断开游标吗_Sql Server_Cursor - Fatal编程技术网

Sql server 有人能解释一下如何在SQLServer中用示例代码手动断开游标吗

Sql server 有人能解释一下如何在SQLServer中用示例代码手动断开游标吗,sql-server,cursor,Sql Server,Cursor,1) 有人能解释一下如何在sql server中手动断开游标吗 2) 任何示例代码 使用变量停止循环 下面是我通常使用的模式 WHILE 1 = 1 BEGIN FETCH NEXT FROM SomeCursor INTO ... IF @@FETCH_STATUS = -1 BREAK; --some processing here IF <some-condition-here> = -1 BREAK; --some additional

1) 有人能解释一下如何在sql server中手动断开游标吗 2) 任何示例代码

使用变量停止循环


下面是我通常使用的模式

WHILE 1 = 1
BEGIN
    FETCH NEXT FROM SomeCursor INTO ...
    IF @@FETCH_STATUS = -1 BREAK;
    --some processing here
    IF <some-condition-here> = -1 BREAK;
    --some additional processing here
END;

“打断光标”是什么意思。退出游标循环?在游标提取期间导致错误?是的,我需要在条件为false时“退出游标循环”最好的方法是从一开始就避免使用光标。通过谷歌搜索可以找到的数千个样本没有帮助?可能重复的@@FETCH_STATUS=-1表示“FETCH语句失败或行超出结果集”。据我所知,当条件为false时“退出光标循环”不是op的意思“@Dudi Konifino,
BREAK
可用于在任何情况下退出循环。我将在示例中添加一个额外的中断以使其更清楚。
WHILE 1 = 1
BEGIN
    FETCH NEXT FROM SomeCursor INTO ...
    IF @@FETCH_STATUS = -1 BREAK;
    --some processing here
    IF <some-condition-here> = -1 BREAK;
    --some additional processing here
END;
FETCH NEXT FROM SomeCursor INTO ...
WHILE @@FETCH_STATUS = 0
BEGIN
    --some processing here
    IF <some-condition-here> = -1 BREAK;
    --some additional processing here
    FETCH NEXT FROM SomeCursor INTO ...
END;