sqlserver 游标操作,给表添加一行行号列,以及可读可写游标定义



if (object_id('proc_temp', 'P') is not null)
drop proc proc_temp
go
create proc proc_temp
with recompile
as
DECLARE @nLine int,@courntNum int ;
DECLARE @cur cursor;
set @cur = cursor forward_only for
SELECT id from BaseDimValue for update of id
open @cur;

set @nLine = 0;
set @courntNum = (select count(*) from BaseDimValue);
fetch next from @cur ;
while @nLine <=@courntNum --@@fetch_status = 0
begin
set @nLine = @nLine + 1;
update BaseDimValue set id = @nLine where current of @cur;
print 'ID值为'+ convert(varchar, @nLine);
fetch next from @cur ;
end
close @cur;
set @nLine = 0;
deallocate @cur;
go

exec proc_temp ;



[size=x-small]1.定义一个标准游标:

declare mycursor cursor for select * from yuangong
2.定义一个只读游标:
declare mycursor cursor for select * from yuangong for read only

3.定义一个可写游标:
declare mycursor1 cursor for select * from yuangong for update of
姓名,性别,年龄,基本工资,奖金,所得税,应发工资
注: scroll 只能对只读游标起作用[/size]

游标定义 请参照 [url]http://www.cnblogs.com/Dlonghow/archive/2009/05/14/1456910.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

annan211

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值