create or replace package types 
  as 
    type p_cursor is ref cursor;---类型 
  end; 
  create or replace procedure query(v_sql varchar2,records out types.p_cursor) 
  as 
    begin 
      open records for v_sql; 
    end; 
  --通过程序块调用存储过程进行展现,但报"rs不是过程或尚未定义"错误 
  declare 
    allr number; 
    rs types.p_cursor; 
  begin 
    query('select * from dept',rs); 
    --如果只执行下面的输出,是正确的 
    dbms_output.put_line(rs%rowcount); 
    ----执行下面报"rs不是过程或尚未定义"错误,为什么 
    for i in rs 
      loop 
          dbms_output.put_line(i.deptid||'---'||i.deptname); 
      end loop; 
    
  end; 

解决方案 »

  1.   

    http://topic.csdn.net/u/20090313/17/8ba17046-c46b-44fc-bf56-0d6a66b712c4.html
      

  2.   

    declare
        allr number;
        rs types.p_cursor;
        cid number; 
        cname varchar2(20);
     begin
    query('select custid,custname from cust',rs);
    loop 
       fetch rs into cid,cname ;   
            exit when rs%notfound;  
    dbms_output.put_line(cid);
    dbms_output.put_line(cname);
     end loop;
    close rs;
    end;
      

  3.   

    declare 
        allr number; 
        rs types.p_cursor; 
        v_deptid number;
        v_deptname varchar2(100);
    begin 
        query('select deptid,deptname from dept',rs); 
        loop 
              fetch deptid,deptname into v_deptid,v_deptname;
              exit when rs%notfound;
              dbms_output.put_line(deptid||'---'||deptname); 
        end loop; 
    end; 
      

  4.   

    declare 
        allr number; 
        rs types.p_cursor; 
        v_deptid number; 
        v_deptname varchar2(100); 
    begin 
        query('select deptid,deptname from dept',rs); 
        loop 
              fetch deptid,deptname into v_deptid,v_deptname; 
              exit when rs%notfound; 
              dbms_output.put_line(deptid||'---'||deptname); 
        end loop; 
    end;