游标实例
DECLARE @LegalUnitID as varchar(100),
@ViewID as varchar(100)
declare my_cursor cursor for
select LegalUnitID,ViewID from T_TEMPLATE_VIEW group by LegalUnitID,ViewID
--打开游标--
open my_cursor
--开始循环游标变量--
fetch next from my_cursor into @LegalUnitID ,@ViewID
while @@FETCH_STATUS = 0 --返回被 FETCH语句执行的最后游标的状态--
begin
--处理
print '@LegalUnitID:'+@LegalUnitID+';@ViewID:'+@ViewID
fetch next from my_cursor into @LegalUnitID,@ViewID --转到下一个游标,没有会死循环
end
close my_cursor --关闭游标
deallocate my_cursor --释放游标