我有以下代碼:PLSQL「錯誤遊標已打開」
DECLARE
f_cd fee.fee_cd%type;
f_name fee.fee_nm%type;
f_new_cd fee.new_fee_cd%type;
f_new_name fee.new_fee_nm%type;
Cursor cur is
SELECT Fee_cd, fee_nm, new_fee_cd, new_fee_nm FROM Fee;
BEGIN
if cur%ISOPEN then
close cur;
end if;
open cur;
for rec in cur loop
fetch cur INTO f_cd, f_name, f_new_cd, f_new_name;
dbms_output.put_line ('The Fee Code ' || f_cd
|| ' is the one you selected and it''s name is '
|| f_name);
end loop;
close cur;
END;
但我不斷收到錯誤消息
原因:試圖打開的遊標已經打開。
操作:重新打開前先關閉光標。
我不知道發生了什麼事。當我更改代碼以刪除for loop
並僅使用loop... end loop
結構時,它可以工作。以下功能代碼:
loop
fetch cur INTO f_cd, f_name, f_new_cd, f_new_name;
dbms_output.put_line ('The Fee Code ' || f_cd
|| ' is the one you selected and it''s name is '
|| f_name);
exit when cur%notfound;
end loop;
close cur;
END;
爲什麼當我使用for循環時,它是否告訴我光標已經打開?