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

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

问题描述

与主题中的一样。我可以简单地将光标的位置重置为Transact-SQL的开头,以便它可以再次在表上运行吗?我想在以下情况下重置它:

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


推荐答案

您需要将光标声明为滚动,像这样

you need to declare your cursor as scroll, like this

declare c scroll cursor for (select statement); 

然后随时使用以下

fetch first from c;

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

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