DECLARE
miceCursor
cursor
/*
声明游标,默认为FORWARD_ONLY游标
*/
FOR SELECT code,num FROM t1
OPEN miceCursor /* 打开游标 */
FETCH NEXT from miceCursor into @code , @num /* 读取第1行数据 */
WHILE @@FETCH_STATUS = 0 /* 用WHILE循环控制游标活动 */
begin
while @i < @num
begin
insert into t2(code) values ( @code )
set @i = @I + 1
end
set @i = 0
FETCH NEXT from miceCursor into @code , @num /* 读取下一行数据 */
end
CLOSE miceCursor /* 关闭游标 */
DEALLOCATE miceCursor /* 删除游标 */
FOR SELECT code,num FROM t1
OPEN miceCursor /* 打开游标 */
FETCH NEXT from miceCursor into @code , @num /* 读取第1行数据 */
WHILE @@FETCH_STATUS = 0 /* 用WHILE循环控制游标活动 */
begin
while @i < @num
begin
insert into t2(code) values ( @code )
set @i = @I + 1
end
set @i = 0
FETCH NEXT from miceCursor into @code , @num /* 读取下一行数据 */
end
CLOSE miceCursor /* 关闭游标 */
DEALLOCATE miceCursor /* 删除游标 */