t-sql 游标:“首先从”获取重新生成光标的内容?
我有一段别人的代码,基本上是这样做的:
declare X cursor static for select * from stuff
open cursor X
fetch next from X
while @@fetch_status = 0
begin
do stuff
fetch next from X
end
fetch first from X
while @@fetch_status = 0
begin
do different stuff
fetch next from X
end
为了让它摆脱困境,是的,我知道游标不好/不再流行/等等。我没有写它。我只需要修复它。现在的问题是:
如果底层游标后面的数据在第一个循环和第二个循环之间发生变化,第二个游标循环是否会看到与第一个游标循环不同的数据?或者静态限定符会阻止这种情况吗?
I have a block of someone else's code that does essentially this:
declare X cursor static for select * from stuff
open cursor X
fetch next from X
while @@fetch_status = 0
begin
do stuff
fetch next from X
end
fetch first from X
while @@fetch_status = 0
begin
do different stuff
fetch next from X
end
To get it out of the way, yes, I know cursors are bad / no longer in fashion / etc. I didn't write it. I just have to fix it. Now to the question:
If the data behind the underlying cursor changes between the first loop and the second loop, could the second cursor loop see different data than the first cursor loop? Or does the static qualifier prevent that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
游标检索到的数据不会改变。如此处所述:
The data retrieved by the cursor will not change. As documented here: