用游标取a表中的数据更新b表

-- 定义游标
declare @i int;
declare m_cursor cursor scroll for select student_num from gd_student for update;
-- 打开游标
open m_cursor;
set @i = 1;
declare @student_num bigint;
--填充数据
fetch next from m_cursor into @student_num
--假如检索到了数据,才处理
while @i<14--@@FETCH_STATUS=0
begin
update gd_experiment set student_num=@student_num where experiment_id=@i;
set @i = @i + 1;
--填充下一条数据
fetch next from m_cursor into @student_num;
end
-- 关闭游标
close m_cursor;
--释放游标
deallocate m_cursor;

posted @ 2018-09-05 17:43  net5x  阅读(206)  评论(0)    收藏  举报