首页 > 解决方案 > 另一种光标模板

问题描述

我最近偶然发现了以下游标实现:

open cursor
while 1=1
begin
    fetch next
    if @@fetch_status <> 0 break
   
    (cursor logic here)

end

这对我来说似乎更清晰,模板代码随处可见,其中包括两个相同的 FETCH:

open cursor
fetch next
while @@fetch_status = 0
begin
    (cursor logic here)
    fetch next
end

第二次写作有什么好处吗?

标签: sql-servertsqlcursor

解决方案


推荐阅读