练习使用游标,如下:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROCEDURE testCursor
AS
declare @temp varchar(20)
declare mycursor cursor --定义游标名为mycursor
for
select org_id from dbo.p_organization_bak
open mycursor --打开游标
fetch next from mycursor into @temp --读取第一行数据
while @@fetch_status = 0 --用while控制游标活动
begin
print @temp
fetch next from mycursor into @temp
end
close mycursor ---关闭游标
deallocate mycursor ---释放游标
GO