存储过程中就一个select语句 比如 select A1,A2 from A
想把这个sql文的数据通过一个数组返回,请高手指点。

解决方案 »

  1.   

    create or replace procedure test_pro(curtest out SYS_REFCURSOR) as
       vdata tj_test%rowtype;
    begin
      open curtest for select a1,a2 ... from A;
      loop
        fetch curtest into vdata;
         exit when curtest%notfound;
        dbms_output.put_line(vdata.id);
      end loop;
      close curtest;  
    end test_pro;
      

  2.   

    vdata tj_test%rowtype;
    报错:Item Ignored
    这是什么问题?还要建别的东西吗?
      

  3.   

    create or replace procedure test_pro(curtest out SYS_REFCURSOR) as
       vdata A%rowtype;
    begin
      open curtest for select a1,a2 ... from A;
      loop
        fetch curtest into vdata;
         exit when curtest%notfound;
        dbms_output.put_line(vdata.a1);
      end loop;
      close curtest;  
    end test_pro;
      

  4.   

    但是执行到fetch curtest into vdata;这句就停住 一直不动了
    A表里是有数据的 为什么?
      

  5.   


    create or replace procedure test_pro(curtest out SYS_REFCURSOR) asbegin
      open curtest for select a1,a2 ... from A;
    end test_pro;--调用
    declare
    vdata A%rowtype;
    cur SYS_REFCURSOR;
    begin
    test_pro(cur);
      loop
        fetch curtest into vdata;
         exit when curtest%notfound;
        dbms_output.put_line(vdata.a1||' '||vdata.a2||' '||....);
      end loop;
      close cur;
    end;
      

  6.   


    一个例子
    SQL> set linesize 120
    SQL> var cur refcursor;
    SQL> begin
      2  open :cur for select * from tuserinfo where rownum <5 ;
      3  end;
      4  /PL/SQL 过程已成功完成。SQL> print cur;