日期:2014-05-17  浏览次数:20916 次

关于游标通过while遍历的问题
declare
 tempsal drp.t_client.name%type;
 cursor v_mycursor is select *from drp.t_client where id>tempsal;
 v_currecord v_mycursor%rowtype;
begin
  tempsal:=10000;
  open v_mycursor;
  fetch v_mycursor into v_currecord;
  while 
  v_mycursor%found
  loop
  dbms_output.put_line(v_currecord.name);
  fetch v_mycursor into v_currecord;
  end loop;
  close v_mycursor;
end;

假如我去掉红色的那句,运行的时候就会报:buffer overflow, limit of 10000bytes
不去掉运行就正常了
但是我想问的是我前面不是已经把游标取出来了吗,后面循环的时候为什么还要去取

------解决方案--------------------
while 
v_mycursor%found
----------------
为什么用While 判断游标记录存在 ,

open c_job;
loop

fetch c_job into c_row;
exit when c_job%notfound;
dbms_output.put_line(c_row.empno||'-'||c_row.ename||'-'||c_row.job||'-'||c_row.sal);
end loop;
--关闭游标
close c_job;
------解决方案--------------------
红色的就可以理解为 取值啊 就是把游标里的东西 一条条放到你的变量里

不在循环里放那句的话,那就只是取了第一条的值,后面的都没取到