给你一个例子吧,自己依瓢画葫芦吧:
create or replace procedure sql_test (pi1 number,po out sys_refcursor) is  
begin  
  if pi1=1 then
  open po for 'select 1 id,''Tom'' nm from dual union all select 2 id,''Jack'' from dual';  
  else
  open po for 'select 3 id,''Lucy'' nm from dual union all select 4 id,''Lily'' from dual'; 
  end if;
end ; 
/
 
--调用
set serveroutput on;
    declare  
      cur1 SYS_REFCURSOR;   
     id number; 
     nm varchar2(100);
     begin  
       sql_test(1,cur1);  
     loop  
       fetch cur1 into id,nm;  
       exit when cur1%notfound;  
     dbms_output.put_line(id||':'||nm);  
     end loop;  
     close cur1;  
     end;  
/

解决方案 »

  1.   

    我的意思是,在sql_test中就将数据插入到表中去
      

  2.   

    要是insert的话没必要使用游标吧
    直接insert select就插入进去了啊
    insert into T(C1,C2,C3)SELECT C1,C2,C3 FROM temp
      

  3.   

    游标也要用,insert也要用,最好能从游标中取数
      

  4.   

    TYPE outcursor IS REF CURSOR;procedure AAAAA(
                                               prm_cur  out  outcursor ,   -- 主数据游标
                                               prm_orgName out VARCHAR2
      )
      isbegin
    ......
    open  prm_cur  for 
    select * from  A  where 。。
    union all
    select * from  B  where 。。
    union all
    select * from  C  where 。。【我插入的代码段】end;我想在存储过程里面open完游标以后,使用游标中的数据,插入到另一张表中,,这个地方改泽尔写啊?我自己写了一个如下:

       FOR aaa IN prm_cur LOOP
          begin
           INSERT INTO ......
          exception when others then
             null;
          end;
       END LOOP;
    】错误:PLS-00221: 'PRM_CUR' 不是过程或尚未定义
    行:480
    文本:FOR c_cur_vehmodel IN prm_cur LOOP这种情况我该怎么写啊?
      

  5.   

    declare
    A outcursor;
    V_R A%ROWTYPE;
    BEGIN
    AAAAA(A,prm_orgName);--第一个参数为游标,第二个参数根据你的需要写
    loop
    fetch A INTO V_R;
    EXIT WHEN A %NOTFOUND;      begin
           INSERT INTO ......
          exception when others then
             null;
          end;END LOOP;
    CLOSE A;
    END;