嗨,这是我的示例代码。
我需要将两个程序中的数据一起插入而不是一个接一个地插入..这个代码从第一个过程插入数据第一个,然后从第二个插入第一个已经结束插入的行号。请建议一个我可以将数据全部插入而不是按顺序插入的方式。
create or replace package body help
as
procedure main_proc(param1 number,param2 number,v1 out number,v2 out number)
is
v_resultset help.cursortype-->this is defined in the package spec
v_name varchar2(10);
v_code varchar2(40);
begin
v1:=param1;
v2:=param2;
proc1(v1,v_resultset);
LOOP
FETCH v_resultSet INTO v_name;
EXIT WHEN v_Resultset%NOTFOUND;
Dbms_Output.Put_Line('Error in Proc1');
INSERT INTO temp_table(name) values(v_name) ;
END LOOP;
proc2(v1,v2,v_resultset);
LOOP
FETCH v_resultSet INTO v_code;
EXIT WHEN v_Resultset%NOTFOUND;
Dbms_Output.Put_Line('Error in Proc2');
INSERT INTO temp_table(code) values(v_code) ;
END LOOP;
end main_proc;
proc1(v_name VARCHAR2,r_resultset out help.cursortype)
is
begin
open r_resultset for
select name from emp where dept_id=2;
end;
proc2(v_name VARCHAR2,v_code VARCHAR2,r_resultset out help.cursortype)
is
begin
open r_resultset for
select code from code_table where dept_id=3;
end;
end help;
我需要将数据全部插入而不是按顺序插入到我的全局临时表中。
此过程插入如下数据: 名称代码
克拉克(null)而我希望将其插入为
名称代码
克拉克001
琼斯002
史密斯003
亚当004
procedure packagecategory_info(p_item_cat number,p_item_sub_cat number,p_pack_cat_id number,package_sub_cat number,pc_Resultset out Master_Product_Report.cursortype)
is
begin
if p_item_sub_cat is null and p_pack_cat_id is null and package_sub_cat is null then
open pc_Resultset for
Select Name From Packagecategory Where Itemcategory_Id in (select id from itemcategory start with id=p_item_cat connect by prior id=parent_id);
elsif p_pack_cat_id is null and package_sub_cat is null then
open pc_Resultset for
Select Name From Packagecategory Where Itemcategory_Id In (Select Id From Itemcategory Where Parent_Id Is Not Null Start With Id=P_Item_Sub_Cat Connect By Prior Id=Parent_Id);
Elsif Package_sub_Cat Is Null Then
open pc_Resultset for
select name from packagecategory start with id=p_pack_cat_id connect by prior id=parent_id and level_id !=3;
Else
open pc_Resultset for
select name from packagecategory where id=package_sub_cat;
end if;
End packagecategory_info;
----- Main procedure in which above proc would be called
create or replace
package body Master_Product_Report as
procedure Product_Report (p_item_cat number,p_sub_cat number,p_pack_cat_id number,p_pack_sub_cat_id number,p_pack_id number,v1 out number,v2 out number,v3 out number,v4 out number,v5 out number)
is
----------
--some code--
packagecategory_info(v1,v2,v3,v4,v_resultSet);
Loop
Fetch V_Resultset Into V_Pack_cat_Name;
EXIT WHEN v_Resultset%NOTFOUND;
Dbms_Output.Put_Line('Error in Proc2');
INSERT INTO MASTER_PRODUCT_TABLE(PACKAGE_SUB_CAT_NAME) values(v_pack_cat_name) ;
END LOOP;
答案 0 :(得分:0)
如果我最终做对了:
proc1(v1, v_names);
proc2(v1, v2, v_codes);
LOOP
FETCH v_names INTO v_name;
FETCH v_codes INTO v_code;
EXIT WHEN v_names%NOTFOUND;
EXIT WHEN v_codes%NOTFOUND;
INSERT INTO temp_table(name, code) values(v_name, v_code);
END LOOP;
close v_names;
close v_codes;
请注意,procs返回的行数相等取决于您。如果行数大于代码数,则某些员工不会被插入temp_table。