Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

SqlServer游标中使用continue的注意事项 Sql数据库 Sqlserve SqlServer游标 continue

$
0
0

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

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,否则会死循环


Viewing all articles
Browse latest Browse all 3160

Trending Articles