用游标取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;

浙公网安备 33010602011771号