create or replace procedure PRO_PRODUCTQTYCALC(VfactNo in varchar2,Vyyyymm in varchar2,Vretrun out varchar2)
is
cursor C1 is
select a.order_no,b.product_no,a.purchase_date,b.inner_qty
from inner_order_m a,inner_order_d b
where a.fact_no = b.fact_no
and a.inorder_no = b.inorder_no
and substr(a.purchase_date,1,6) = Vyyyymm
and a.fact_no = VfactNo ;
cursor C2(productNo varchar2) is
select mark,mat_no,weight
from product_bomd
where fact_no = VfactNo
and mark =
(
select mark from product_bomm where fact_no = VfactNo
and product_no = productNo
) ;
c_2 C2%rowtype;
cursor C3(mats_no varchar2) is
select mat_no,weight
from mat_sd
where fact_no = VfactNo
and mats_no = mats_no;
c_3 C3%rowtype;
Vc_ops char(1) := 0 ;
begin
for cprod in C1 loop
open C2(cprod.product_no);
loop
fetch C2 into c_2;
exit when C2%notfound;
open C3(c_2.mat_no);
loop
fetch C3 into c_3;
exit when C3%notfound;
if C3%found then
insert into TEMPQTYCAL(mat_no,qty)
values (c_3.mat_no,nvl(cprod.inner_qty,0)*c_2.weight*c_3.weight);
elsif C3%notfound then
insert into TEMPQTYCAL(mat_no,qty)
values (c_2.mat_no,nvl(cprod.inner_qty,0)*c_2.weight);
end if;
end loop;
close C3;
end loop;
close C2;
end loop;
insert into matdosage(fact_no,mm,mat_no,qty)
select VfactNo,Vyyyymm, mat_no,sum(qty) qty
fromTEMPQTYCAL
group by mat_no;
commit;
Vretrun := Vretrun ||'成功';
end PRO_PRODUCTQTYCALC; |