declare
  cursor c_s is select * from test1;
  re test1%rowtype;
 begin
 open c_s;
 loop
   fetch c_s into re;
   dbms_output.put_line(re.price);
   exit when c_s%notfound;
 end loop;
 dbms_output.put_line(c_s%rowcount);
 close c_s;
 end;这样一段程序,结果:
37
45.6
45.6
2test1表中只有两条记录,对应的price字段的值是,37,45.6 
但是游标去弄出了三个记录,但是rowcount显示的仍然是2,是咋回事啊?

解决方案 »

  1.   

    declare 
      cursor c_s is select * from test1; 
      re test1%rowtype; 
    begin 
    open c_s; 
    loop 
      fetch c_s into re;
      exit when c_s%notfound;  
      dbms_output.put_line(re.price); 
    end loop; 
    dbms_output.put_line(c_s%rowcount); 
    close c_s; 
    end; 
      

  2.   

    你的实际上就是输出了2条记录的值,只不过exit when c_s%notfound;放到了输出语句之后。因此notfound时并没有马上退出,而是又输出了一次前面的值。你看看后两条是不是重复了
    按楼上的改下顺序就好