游标
declare @ID int, @PID int, @Ver intdeclare #cur cursor for select 1 as ID,1 as ParentId,1 as Versionunion select 2, 1, 2 union select 3, 1, 3open #curfetch next from #cur into @ID, @PID, @Verwhile @@FETCH_STATUS=0begin print('do some thing.') fetch next from #cur into @ID, @PID, @Verendclose #curdeallocate #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/archive/2009/02/10/1387250.html
相关资源:Mysql中sql语句游标详解