对查询结果进行循环赋值给变量,使用赋值后的变量进行相应的sql操作。
sql语句如下:
-- 定义变量 @user_id DECLARE @user_idINT -- 定义CURSOR CURTB DECLARE CURTB CURSOR FOR SELECT id from user -- 开启 CURTB OPEN CURTB FETCH NEXT FROM CURTB INTO @user_id WHILE(@@FETCH_STATUS=0) BEGIN insert into user_temp select * from user; FETCH NEXT FROM CURTB INTO @user_id END CLOSE CURTB DEALLOCATE CURTB
热门文章