国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 数据库 > 数据库应用 > sql 中游标的使用

sql 中游标的使用

来源:程序员人生   发布时间:2014-12-12 08:12:00 阅读次数:3283次
declare @id int
declare @addTime datetime
declare cursor1 cursor for         --定义游标cursor1
select id,addtime from MR_Examine              --使用游标的对象(跟据需要填入select文)
open cursor1                       --打开游标
declare @i int
set @i=1
fetch next from cursor1 into @id,@addTime  --将游标向下移1行,获得的数据放入之前定义的变量@id,@name中


while @@fetch_status=0           --判断是不是成功获得数据
begin
if(@i>10)
set @i=1

update MR_Examine set AddTime=DATEADD(DAY,@i*⑴,GETDATE()) where Id=@id                           --进行相应处理(跟据需要填入SQL文)
set @i=@i+1
fetch next from cursor1 into @id,@addTime  --将游标向下移1行
end
close cursor1                   --关闭游标
deallocate cursor1
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生