create or replace procedure up_test(o out sys_refcursor) is
begin
open o for select * from lq_test;
fetch……  之后返回就没数据了,不想多次查询
end;

解决方案 »

  1.   

    create or replace procedure up_test(o out sys_refcursor) is
    begin
    open o for select * from lq_test;
    end;
    可以直接这样写,当你调用存储过程的时候,让它赋值给一个游标,然后取数据就可以了
      

  2.   

    create or replace function test() is
    o  sys_refcursor;
    r a%rowtype;
    begin
    open o for select * from a where id=5;
    fetch o into r;
    if o%fount then 
    insert into b (m) values (r.k);
    end if;
    return o;
    end;  不返回数据,请指教
      

  3.   

    create or replace procedure pr_test(p_id varchar2)
    as
    o sys_refcursor ;
    r emp%rowtype;
    begin
      open o for select * from  a where id=p_id;
      LOOP
       fetch o into r;
       exit when o%notfound ;
       insert into b(m) values (r.k);
       dbms_output.put_line (r.k);
      end loop;
    end;-----------------------------
    begin
     pr_test(5);
    end;这样执行
      

  4.   

    重复的帖子了
    1、 通过 dbms_output.put_line (r.k);可以查看游标取回的数据。PS,执行set serveroutput on
    2、如果在其他session中看的话,注意执行完语句要commit
    3、尽量不要再函数中进行insert,update等操作。建议放到过程中去