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  --释放游标

  

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM