Stored procedures Oracle存储过程-游标内循环
我有一个存储过程1Stored procedures Oracle存储过程-游标内循环,stored-procedures,plsql,oracle10g,cursor,Stored Procedures,Plsql,Oracle10g,Cursor,我有一个存储过程1 在Procedure1中,我调用另一个过程Procedure2,它返回sys\u refcursor procuresult2 我需要遍历该游标的每一行,并将数据插入表中 代码 Create Procedure1() as ProcResult1 Sys_refcursor; begin Procedure2(ProcResult2); For eachrow in ProcResult2 Loop i
Create Procedure1()
as
ProcResult1 Sys_refcursor;
begin
Procedure2(ProcResult2);
For eachrow in ProcResult2
Loop
insert into test_table(ProcResult2.Id);
end loop;
end ;\
任何关于如何实现2的想法和建议。功能?即遍历ProcleSult2中返回的每一行并插入到一个新表中。您就快到了:
Create Procedure1()
as
ProcResult1 Sys_refcursor;
v_record ???; -- See below
begin
Procedure2(ProcResult2);
Loop
fetch ProcResult2 into v_record;
exit when ProcResult2%notfound;
insert into test_table(v_record.Id);
end loop;
close ProcResult2;
end;
您需要使用与游标返回内容匹配的结构声明变量v_记录,即,在构建过程时,您需要知道游标记录的结构。如果光标返回“select*from mytab”,则可以使用:
v_record mytab%rowtype;
但如果它仅选择某些列,例如“从mytab中选择col1、col3”,则需要手动定义结构:
type v_record_type is record (col1 number, col3 varchar2(10));
v_record v_record_type;