SQL SERVER 游标循环读取表数据

【cursor】游标:用于循环表行数据,类似指针

格式如下:

declare tempIndex cursor for (select * from table) --定义游标
open tempIndex  --打开游标
fetch next from tempIndex into @x  --抓取下一行数据给变量
while @@fetch_status=0  --0表示抓取成功,1表示抓取失败,2表示不存在抓取行
begin
--sql 语句
end
close tempIndex  --关闭游标
deallocate tempIndex  --释放游标

猜你喜欢

转载自www.cnblogs.com/itsone/p/10256480.html