oracle存储过程传递游标

大表哥bettercong 2014-11-06 07:46:51

procedure AAAAA(
prm_cur out cursor, -- 主数据游标
prm_orgName out VARCHAR2
)
is

begin
......
open prm_cur for
select * from 。。。。。。;

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

这种情况我该怎么写啊?



...全文
327 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bw555 2014-11-07
  • 打赏
  • 举报
回复
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;

  • 打赏
  • 举报
回复
TYPE outcursor IS REF CURSOR; procedure AAAAA( prm_cur out outcursor , -- 主数据游标 prm_orgName out VARCHAR2 ) is begin ...... 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 这种情况我该怎么写啊?
  • 打赏
  • 举报
回复
游标也要用,insert也要用,最好能从游标中取数
bw555 2014-11-06
  • 打赏
  • 举报
回复
要是insert的话没必要使用游标吧 直接insert select就插入进去了啊
insert into T(C1,C2,C3)SELECT C1,C2,C3 FROM temp
  • 打赏
  • 举报
回复
我的意思是,在sql_test中就将数据插入到表中去
CT_LXL 2014-11-06
  • 打赏
  • 举报
回复
引用 楼主 u012565454 的回复:
给你一个例子吧,自己依瓢画葫芦吧:

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;  
/

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧