SqlServer游标中使用continue的注意事项

时间:2022-07-06 04:37:40
declare @userid int --用户id

declare cur_uid Cursor for select userid from tb_user
Open cur_uid
Fetch Next From cur_uid into @userid
While(@@Fetch_Status = 0)
Begin
Begin
if(@userid=123456)
begin
Fetch Next From cur_uid into @userid --continue之前必须Fetch Next,否则会死循环
continue;
end
--执行select、insert等业务操作
--。。。
End
Fetch Next From cur_uid into @userid
End
Close cur_uid
Deallocate cur_uid

即:

continue之前必须Fetch Next,否则会死循环