关于游标的问题

declare BRItemCusror cursor 
for select BRItemID from RechageItem where State=0 and AccountID=@AccountId;
open BRItemCusror
fetch next from BRItemCusror into @BRItemID;
为什么@@Fetch_Status = -1?  不明白出错在哪  明明定义游标的SQL查询结果是有记录的。

芜湖不芜
浏览 709回答 2
2回答

POPMUISE

游标我的理解就是在SQL中循环,循环肯定是由条件的,修改成下面试试看:declare BRItemCusror cursor for select BRItemID from RechageItem where State=0 and AccountID=@AccountId;open BRItemCusrorwhile    @@fetch_status=0  --结束的条件       begin             fetch next from BRItemCusror into @BRItemID;     endclose   BRItemCusror--关闭游标  deallocate   BRItemCusror另外看一下select BRItemID from RechageItem where State=0 and AccountID=@AccountId; 这里面有东西吗?

达令说

游标一般用一楼那个结构写的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server