Sql语句介绍:游标

游标
declare @ID int@PID int@Ver int
declare #cur cursor for 
select 1 as ID,1 as ParentId,1 as Version
union select 212 union select 313

open #cur
fetch next from #cur into @ID@PID@Ver
while @@FETCH_STATUS=0
begin
    
print('do some thing.')
    
fetch next from #cur into @ID@PID@Ver
end
close #cur
deallocate #cur

其中fetch next from #cur into @ID, @PID, @Ver是读取当前行的记录,按Column的顺序放到这三个变量中。

等同select @ID=ID,@PID=PID,@Ver=Ver from table where 条件.

原文地址:https://www.cnblogs.com/KenBlove/p/1387250.html