读书人

sql server 游标 例证

发布时间: 2012-09-17 12:06:51 作者: rapoo

sql server 游标 例子

练习使用游标,如下:

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

读书人网 >SQL Server

热点推荐