我可以重置光标的位置到开始吗? [英] Can I reset cursor's position to the begining?

查看:193
本文介绍了我可以重置光标的位置到开始吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如主题。我可以简单地将光标的位置重置到Transact-SQL的开头,以便它可以再次在表上运行吗?我想在以下上下文中重置它:
$ b $bÚ

As in the topic. Can I simply reset cursor's position to the beginning in Transact-SQL, so it can run again over the table? I want to reset it in the following context:

DECLARE @userID INT
DECLARE user_cursor CURSOR FOR SELECT userID FROM users

WHILE /* some condition */
BEGIN
...

    FETCH NEXT FROM user_cursor INTO @userID

    IF @@FETCH_STATUS = 0
    BEGIN
        /*... here goes the reset of the cursor ...*/
    END

...
END

/ p>

thanx for any advice.

推荐答案

您需要将光标声明为滚动,如下所示

you need to declare your cursor as scroll, like this

declare c scroll cursor for (select statement); 

然后在任何时候找到第一个只需使用以下

then at any time for locating to the first just use the following

fetch first from c;

这篇关于我可以重置光标的位置到开始吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆