时间:2021-07-01 10:21:17 帮助过:3人阅读
sql server游标:
--定义游标
declare cursor1 cursor for select ID,Name from A
--打开游标
open cursor1
declare @id int
declare @name varchar(50)
declare @n int
declare @i int=1
set @n=(select COUNT(1) from A)
while(@i<@n)
begin
set @i=@i+1
fetch next from cursor1 into @id,@name
select @id select @name
end
--关闭游标
close cursor1
--释放游标,释放后就不能在打开游标了
deallocate cursor1
sql server 游标的简单用法
标签:close 打开 arch 关闭 cursor 定义 count int end