【发布时间】:2014-06-27 07:19:35
【问题描述】:
您好,这是我的示例代码。
我需要将两个程序中的数据全部插入,而不是一个接一个地插入。此代码从第一个程序插入数据,然后从第二个程序插入第一个程序已结束插入的行号。请建议一个我可以通过这种方式将数据全部插入而不是按顺序插入。
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;
我需要将数据全部插入而不是按顺序插入到我的全局临时表中。
此过程插入如下数据: 名称代码
克拉克(空)
琼斯(空)
史密斯(空)
亚当(空)
(空) 001
(空) 002
(空) 003
(空)004
而我希望将其插入为
名称代码
克拉克 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;
【问题讨论】:
-
“将数据全部插入而不是按顺序插入”是什么意思?数据如何存储在表中并不重要,唯一重要的是您在选择期间如何排序。
-
看到我的数据来自不同的表,并且它也被不同的程序获取......所以而不是像......一样显示在表中的数据........姓名->琼斯亚历克斯克拉克,然后从第 4 行插入代码,而不是显示在姓名前面。这就是我的意思。
-
您可以通过 UNION ALL 组合两个查询。此外,您不需要为此使用任何游标和存储过程。只需一条语句即可完成。
-
好吧,这只是我制作的一个小代码,目的是明确我想要做什么,而这是业务需求,代码就像 1500 LOC,无法在此处复制.存储在表中的数据必须显示在前端。要求不能仅通过简单的联合和连接来完成,因此必须以适当的方式存储。希望你能得到我正在寻找的东西。
-
'DISPLAYED IN THE TABLE' 不正确。检索数据时会显示数据。如果您在谈论记录的顺序,那么影响它的唯一方法就是 ORDER BY。
标签: oracle loops stored-procedures plsql oracle-sqldeveloper