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 all_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.   

      query('select * from dept',:rs); 
      

  2.   

     create or replace procedure query(v_sql varchar2,records out types.p_cursor) 
      as 
        begin 
          open records for all_sql
        end; 看看就知道错在哪 了
      

  3.   

    三楼说的对,我疏忽写错了!我改过来了还是这个样子!?
    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 all_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; 
      

  4.   

    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;