declare mycursor cursor for select top 10 id from dbo.table
declare @id intopen mycursorfetch next from mycursor into @id
while @@fetch_status <> 0
begin
print cast(@id as varchar) + 'rrr'
fetch next from mycursor into @id
end
close mycursor
deallocate mycursor这段代码为什么没有print出结果?
sqlserver2005
declare @id intopen mycursorfetch next from mycursor into @id
while @@fetch_status <> 0
begin
print cast(@id as varchar) + 'rrr'
fetch next from mycursor into @id
end
close mycursor
deallocate mycursor这段代码为什么没有print出结果?
sqlserver2005
declare @id int open mycursor fetch next from mycursor into @id
while @@fetch_status = 0
begin
print cast(@id as varchar) + 'rrr'
fetch next from mycursor into @id
end
close mycursor
deallocate mycursor
--
--遊標獲取成功 @@fetch_status = 0
返回值
返回值 说明
0 FETCH 语句成功。
-1 FETCH 语句失败或行不在结果集中。
-2 提取的行不存在。
declare @id int open mycursor fetch next from mycursor into @id
while @@fetch_status =0 -- 改成等于0
begin
print cast(@id as varchar) + 'rrr'
fetch next from mycursor into @id
end
close mycursor
deallocate mycursor