您的位置:首页 > 数据库

SQL游标使用步聚

2016-06-20 00:00 274 查看
当你需要对select出来的结果循环处理的时候就需要用到游标。
如下面的一个存储过程中就用了一个游标:
Create Proc Pr_DeleteTable
as
declare @Table varchar(20)
declare cr_cursor cursor --1.定义游标
for select name from dbo.sysobjects where xtype='U' and status>0
open cr_cursor --2.打开游标
fetch From cr_cursor into @Table --3.提取游标
while @@fetch_status=0
begin
print @Table --执行打印操作
fetch next From cr_cursor into @Table
end;
close cr_cursor --4.关闭游标
deallocate cr_cursor --5.释放游标
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: