首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql server 游标 例证

2012-09-17 
sql server 游标 例子练习使用游标,如下:SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOalter PROCEDURE

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

热点排行