用这种形式看怎样
create or replace procedure cj_test is temp_lbillcode varchar2(20):='';
  cursor   cur_Orders   is  select   lbillcode  from    orders ;
  
begin
  for v_sor in cur_Orders loop
  temp_lbillcode:=v_sor.lbillcode;
  end loop;
end cj_test;

解决方案 »

  1.   

    beckhambobo(beckham):谢谢你的回复,但是我试过了,你的那种写法好象还是一样的结果。
    我把用来测试存储过程的代码也放出来吧:begin
      -- Call the procedure
      cj_test;
    end;我在pl/sql developer中的sessions窗口中看到有未关闭的游标,为什么?
      

  2.   

    我在pl/sql developer中的sessions窗口中看到有未关闭的游标,为什么?
    没有关掉连接的话,当然可以看到游标。
    如果你能够确认没有关闭的游标就是这个存储过程产生的话,结论只有一个:那就是
    temp_lbillcode varchar2(20):=''; 这个变量定义长度定义小了,才会在fetch的时候产生异常,而你的程序没有捕捉异常,所以游标没有关闭。即使表里面没有记录都不会有异常的。
      

  3.   

    create or replace procedure cj_test is
           temp_lbillcode varchar2(20):='';
         declare cursor   cur_Orders   is  select   lbillcode  from    orders ;
    begin
          open cur_Orders;
         fetch cur_Orders into temp_lbillcode;
         while    cur_Orders%found    loop
         fetch cur_Orders into temp_lbillcode;
         end    loop;
        close cur_Orders;
       commit;
    exception
           when INVALID_CURSOR then
    dbms_output.line('Course is error')
          when others then
    null;
    end cj_test;
      

  4.   

    都没有用啊,我把代码改为如下:create or replace procedure cj_test is
           temp_lbillcode varchar2(20):='';
          cursor   cur_Orders   is  select   lbillcode  from    orders ;
    begin
          open cur_Orders;
         fetch cur_Orders into temp_lbillcode;
         while    cur_Orders%found    loop
         fetch cur_Orders into temp_lbillcode;
         end    loop;
        close cur_Orders;
       commit;
      dbms_output.put_line('success');
    exception
         when INVALID_CURSOR then
    dbms_output.put_line('Course is error');
          when others then
    dbms_output.put_line('error');   
    end cj_test;结果输出了success,但还是看到有未关闭的游标,这到底是为什么啊!
      

  5.   

    我看到的未关闭的游标,就是在打开这个存储过程的test窗口的session里的啊。