星空网 > 软件开发 > 数据库

sqlserver 游标的使用

declare @temp_temp uniqueidentifier--临时变量  DECLARE aaa CURSOR for select Id from A-------------------打开游标open aaa--先查询一次再循环,防止有多个游标时@@FETCH_STATUS=-1不能进入下个游标循环的情况fetch next from aaa into @temp_temp-------------------循环取数据while @@FETCH_STATUS=0beginprint @temp_tempfetch next from aaa into @temp_tempend----------------------------------- 关闭游标  Close aaa  ----------------------------------- 删除游标  Deallocate aaa

  

游标的嵌套

declare @temp_temp uniqueidentifier--临时变量  DECLARE aaa CURSOR for select Id from A-------------------打开游标open aaa--先查询一次再循环,防止有多个游标时@@FETCH_STATUS=-1不能进入下个游标循环的情况fetch next from aaa into @temp_temp-------------------循环取数据while @@FETCH_STATUS=0beginprint @temp_temp	--===========================游标嵌套 	DECLARE bbb CURSOR for select Id from B	-------------------打开游标	open bbb	--先查询一次再循环,防止有多个游标时@@FETCH_STATUS=-1不能进入下个游标循环的情况	fetch next from bbb into @temp_temp	-------------------循环取数据	while @@FETCH_STATUS=0	begin	print @temp_temp	fetch next from bbb into @temp_temp	end	----------------------------------- 关闭游标  	Close bbb  	----------------------------------- 删除游标  	Deallocate bbb	--===========================游标嵌套fetch next from aaa into @temp_tempend----------------------------------- 关闭游标  Close aaa  ----------------------------------- 删除游标  Deallocate aaa

  




原标题:sqlserver 游标的使用

关键词:sql

sql
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

2022全球零售力量:https://www.goluckyvip.com/tag/15395.html
2022全球美妆个护未来趋势:https://www.goluckyvip.com/tag/15396.html
2022全球十大消费者趋势:https://www.goluckyvip.com/tag/15397.html
2022全球消费者趋势报告:https://www.goluckyvip.com/tag/15398.html
2022全球小家电趋势洞察白皮书:https://www.goluckyvip.com/tag/15399.html
网易考拉618:https://www.goluckyvip.com/tag/154.html
大同旅游攻略一日游 山西大同一日游旅游景点有哪些:https://www.vstour.cn/a/408251.html
如何从帽儿山到哈尔滨火车站(详细交通路线及注意事项):https://www.vstour.cn/a/408252.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流