--1.声明游标
declare cursor cur is
select t.login_name, t.fk_user_id from t_user_info t;
v_id t_user_info.fk_user_id%TYPE;
v_name t_user_info.login_name%TYPE;
v_count number;
begin
--2.使用loop开始循环
loop
--3.判断游标是否打开
if not cur%ISOPEN THEN
OPEN CUR;
END IF;
--4.将游标中的值赋给对象
fetch cur into v_name, v_id;
select count(1) into v_count from t_uaac_user_role where user_id = v_id;
--5.判断是否存在需要更新的数据,有则执行更新操作
if v_count>0 then
update t_uaac_user_role u
set u.login_name = v_name
where u.user_id = v_id;
commit;
dbms_output.put_line(v_name || ' ' || v_id);
end if;
--6.判断是否循环结束(游标溢出时会引发预定义的NOT FOUND错误)
exit when cur%notfound or cur%notfound is null;
end loop;
close cur;
end;