为什么要获得重复记录?请纠正我。谢谢你。
declare
clazzes_rec clazzes%rowtype;
cursor clazzes_cur is select * from clazzes;
begin
if clazzes_cur%isopen then
dbms_output.put_line('Cursor is not open,trying to Open.... ... .. .');
end if;
open clazzes_cur;
dbms_output.put_line('Cursor opened :');
loop
fetch clazzes_cur into clazzes_rec;
dbms_output.put_line('id:'||clazzes_rec.id||':name:'||clazzes_rec.name);
exit when clazzes_cur%notfound;
end loop;
close clazzes_cur;
end;
输出:
Cursor opened :
id:1:name:leo1
id:2:name:leo2
id:3:name:leo3
id:4:name:leo4
id:4:name:leo4
PL/SQL procedure successfully completed
答案 0 :(得分:5)
只需交换行:
loop
fetch clazzes_cur into clazzes_rec;
exit when clazzes_cur%notfound;
dbms_output.put_line('id:'||clazzes_rec.id||':name:'||clazzes_rec.name);
end loop;
当您获取最后一条记录并尝试获取下一条clazzes_cur%notfound
时,但在它有机会退出循环之前,您将再次输出最后一条记录。