您的位置:首页 > 博客中心 > 数据库 >

SQL 中的游标实例

时间:2022-03-13 23:22

--声明变量
declare @IMType varchar(10),@IMResourceID varchar(10)
--定义游标
declare information_cursor cursor for
select [IMType],[IMResourceID] FROM [BJYX].[dbo].[Information]
--打开游标
open information_cursor
--搜索行,并将数据存储在变量中 
Fetch next from information_cursor into @IMType,@IMResourceID
--遍历结果集开始
 While @@FETCH_STATUS=0
 begin
     --这里面可以对某一行进行想要的处理
      print @IMType+space(2)+@IMResourceID
     
   --继续读取行数据 
    Fetch next from information_cursor into @IMType,@IMResourceID
 end
 --遍历结果集结束
 --关闭游标
 Close information_cursor
 --释放游标
deallocate information_cursor

  

热门排行

今日推荐

热门手游