sql之游标


--select * from   master..sysprocesses
use test
declare my_cursor cursor scroll dynamic --scroll表示可以向前或向后移动   dynamic:表示可写也可读,
for
select F3 from temp --定义my_cursor 游标

open my_cursor --打开游标
declare @name nvarchar(128) --定义一个变量
fetch next from my_cursor into @name --游标停在第一条记录前面,第一次执行,测试有没有记录存在
while(@@fetch_status=0) --取数据,直到-2即没有记录
begin
print '姓名: ' + @name 
--fetch next from my_cursor
fetch next from my_cursor into @name
end

--fetch first from my_cursor into @name
print @name
 --update temp set F9='zzg' where current of my_cursor 
/* delete from 个人资料 where current of my_cursor */
close my_cursor
deallocate my_cursor

posted @ 2015-08-26 10:08  nick.flyrong  阅读(120)  评论(0编辑  收藏  举报