declare --聲明兩個變量
v_id VARCHAR2(50);
v_int number;
cursor yb is
select a.id from T_D5_PUNISHMENT a where a.removed = '0';
begin
v_int := 1; --變量賦值
open yb; --打開游標
loop --開始標記
fetch yb into v_id; --游標賦值 當然這邊可以賦值多個值
(譬如:fetch yb into v_id , v_name;)
exit when yb%notfound; --游標一條一條地遍歷記錄,當找不到記錄時退出
begin
update T_D5_PUNISHMENT a set a.cardtype= case a.cardtype when '02' then '01' when '03' then '02' when '04' then '05' else '' end --實際操作
where a.id=v_id;
exception --異常拋出
when others then
dbms_output.put_line(v_id);
end;
v_int := v_int+1;
if(v_int >=500) then
commit; --500條提交一次 分單系統壓力,提高上傳的效率
v_int :=0;
end if;
end loop; --結束標記
commit;
close yb; --關閉游標
end; --結束
/ --這個斜杠用處很大,比如好多條存儲過程的話,可以寫在后面一起執行。
————————————————
原文鏈接:https://blog.csdn.net/z1729734271/java/article/details/52351700