SQL Server 游标
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | declare @id int --定义接收变量 declare @ name nvarchar(20) --定义接收变量 declare type_cur cursor static --定义游标[static:静态游标] for select id,type_name from ST_Type open type_cur fetch next from type_cur into @id,@ name --循环游标 while @@FETCH_STATUS =0 --假如检索到了数据继续执行 begin ---------------逻辑开始部分----------------- print @ name if(@id=2) begin update ST_Type set type_name= '测试:' +type_name where id=3 end ---------------逻辑结束部分----------------- fetch next from type_cur into @id,@ name --获取下一条数据并赋值给变量 end close type_cur --关闭游标 deallocate type_cur --删除游标 |
在数据比较多的情况下使用游标会造成读取数据缓慢或者运行错误
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了