可另做一个存储过程,将游标遍历一遍,将记录转成表变量,然后返回。SQL Server的示例脚本如下:
/*
-- 返回游标的存储过程
alter proc GetCursor1 (@Cursor1 cursor varying output) as
begin
set @Cursor1 = cursor for select * from T1 where ID in (1,2,5)
open @Cursor1
end
*/
create proc sp_2 as
begin
declare @f1 int,@f2 nvarchar(50)
declare @t table(ID int,Name nvarchar(50))
declare @Cursor1 cursor
-- 调用存储过程
exec GetCursor1 @Cursor1 output
fetch next from @Cursor1 into @f1,@f2
while @@FETCH_STATUS=0
begin
insert into @t(ID,Name)Values(@f1,@f2)
fetch next from @Cursor1 into @f1,@f2
end
close @Cursor1
deallocate @Cursor1
select * from @t
end
|