- 浏览: 164357 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
钱少少:
programming 写道和maven相比没优势
ivy只是 ...
ant+ivy管理项目 -
programming:
和maven相比没优势
ant+ivy管理项目 -
钱少少:
kingsfighter 写道和maven相比,有什么优势?
...
ant+ivy管理项目 -
kingsfighter:
和maven相比,有什么优势?
ant+ivy管理项目 -
zhijie_zhang:
搭建java-web框架(一)
pl-sql中函数的输出
一函数例子:
CREATE OR REPLACE FUNCTION "F_TEST"( p_areaid in number,
p_prodid in number,
p_year in number,
p_month in number)
return table_ztdomesticdemandaudit
/*
reportnames */
pipelined is
pragma autonomous_transaction;
v_row_ztdomesticdemandaudit ROW_ZTDOMESTICDEMANDAUDIT;
months varchar2(32);
v_xilie varchar2(128);
v_pinpai varchar2(128);
v_jihuapinpai varchar2(128);
v_prodcode varchar2(32);
v_prodname varchar2(512);
v_gbjx number(16) := 0;
v_gbpt number(16) := 0;
v_bmjx number(16) := 0;
v_bmpt number(16) := 0;
v_qyjx number(16) := 0;
v_qupt number(16) := 0;
v_ywyjx number(16) := 0;
v_ywypt number(16) := 0;
v_khjx number(16) := 0;
v_khypt number(16) := 0;
v_qty1 number(16);
v_qty2 number(16);
v_qty3 number(16);
v_mess varchar2(512) := '';
v_adjustqty1 number(16) := 0;
v_adjustqty2 number(16) := 0;
v_prodid number(16);
v_areaid number(16);
v_plancustomertype number(16);
---------------------------------------------------------
begin
for c1 in (select to_char(a.AUDITDATE, 'yyyy-mm') as months,
d.valuename as xl, --系列
pb.brandname AS pp,
dd.valuename as jhpp,
p.prodcode,
pl.prdn,
p.prodid,ba.areaid,a.plancustomertype
--a.DEMANDQTY1
from ztdomesticdemandaudit a,
product p,
dictionary d,
dictionary dd,
productlang pl,
productbrand pb,
businessarea ba
where 1 = 1
and a.prodid = p.prodid
and p.prodid = pl.prodid
and p.brandcode = pb.brandcode
and pl.languagecode = pb.languagecode
and pl.languagecode = 'cn'
and a.plancustomertype in (1, 2)
and a.areaid = ba.areaid
and p.ztprodseries = d.value
and d.type = 'ZTTyreSeries'
and d.languagecode = 'cn'
and p.ztplanbrand = dd.value(+)
and dd.type(+) = 'ZTPlanBrand'
and dd.languagecode(+) = 'cn'
and ba.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba.areaid)
connect by parentareaid = prior areaid)
-- and a.plancustomertype =
-- nvl(p_plancustomertype, a.plancustomertype)
and to_char(a.auditdate, 'yyyy') =
nvl(p_year, to_char(a.auditdate, 'yyyy'))
and to_char(a.auditdate, 'mm') =
nvl(p_month, to_char(a.auditdate, 'mm'))
and p.PRODID = nvl(p_prodid, p.PRODID)
order by a.prodid) loop
months := c1.months;
v_xilie := c1.xl;
v_pinpai := c1.pp;
v_jihuapinpai := c1.jhpp;
v_prodcode := c1.prodcode;
v_prodname := c1.prdn;
v_prodid := c1.prodid;
v_areaid :=c1.areaid;
v_plancustomertype :=c1.plancustomertype;
--v_qty1:=c1.DEMANDQTY1;
--adjustqty 1
if v_plancustomertype = 1 then
begin
select nvl(adjustqty, 0)
into v_adjustqty1
from ztdomesticdemandadjust zt,
ztdomesticdemand zc,
ztdomesticdemanddetail zcd
where zc.orgid = zt.orgid
and zc.partnerid = zt.partnerid
and zcd.prodid = zt.prodid
and to_char(zt.adjustdate, 'yyyy') =
nvl(to_char(months,'yyyy'), to_char(zt.adjustdate, 'yyyy'))
and to_char(zt.adjustdate, 'mm') =
nvl(to_char(months,'mm'), to_char(zt.adjustdate, 'mm'))
-- and zt.prodid = nvl(p_prodid, zt.prodid)
and zt.prodid=nvl(v_prodid,zt.prodid)
and zc.PLANCUSTYPE = 1;
exception
when others then
v_adjustqty1:= 0;
end;
elsif v_plancustomertype = 2 then
--adjustqty 2
begin
select nvl(adjustqty, 0)
into v_adjustqty2
from ztdomesticdemandadjust zt,
ztdomesticdemand zc,
ztdomesticdemanddetail zcd
where zc.orgid = zt.orgid
and zc.partnerid = zt.partnerid
and zcd.prodid = zt.prodid
and to_char(zt.adjustdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(zt.adjustdate, 'yyyy'))
and to_char(zt.adjustdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(zt.adjustdate, 'mm'))
-- and zt.prodid = nvl(p_prodid, zt.prodid)
and zt.prodid=nvl(v_prodid,zt.prodid)
and zc.PLANCUSTYPE = 2;
exception
when others then
v_adjustqty2:= 0;
end;
end if;
--gbjx
begin
select nvl(a1.balanceqty,0)
into v_gbjx
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and plancustomertype = 1
and ba1.grade = 2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_gbjx:= 0;
end;
v_gbjx := v_gbjx + v_adjustqty1;
--gbpt
begin
select nvl(a1.balanceqty,0)
into v_gbpt
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and plancustomertype = 2
and ba1.grade = 2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_gbpt:= 0;
end;
v_gbpt := v_gbpt + v_adjustqty2;
--bmjx
begin
select nvl(a1.balanceqty,0)
into v_bmjx
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and plancustomertype = 1
and ba1.grade = 3
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_bmjx:= 0;
end;
v_bmjx := v_bmjx + v_adjustqty1;
--bmpt
begin
select nvl(a1.balanceqty,0)
into v_bmpt
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and a1.plancustomertype = 2
and ba1.grade = 3
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_bmpt:= 0;
end;
v_bmpt := v_bmpt + v_adjustqty1;
--qyjx
begin
select nvl(a1.balanceqty,0)
into v_qyjx
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and a1.plancustomertype = 1
and ba1.grade = 4
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_qyjx:= 0;
end;
v_qyjx := v_qyjx + v_adjustqty1;
--qypt
begin
select nvl(a1.balanceqty,0)
into v_qupt
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and a1.plancustomertype = 2
and ba1.grade = 4
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_qupt:= 0;
end;
v_qupt := v_qupt + v_adjustqty2;
--ywyjx
begin
SELECT nvl(b.SALESBALANCEQTY,0)
into v_ywyjx
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 1;
exception
when others then
v_ywyjx:= 0;
end;
--
/* select sum(a1.balanceqty) into v_ywyjx from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=1
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_ywyjx := v_ywyjx + v_adjustqty1;
--ywypt
begin
SELECT nvl(b.SALESBALANCEQTY,0)
into v_ywypt
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 2;
exception
when others then
v_ywypt:= 0;
end;
--
/* select sum(a1.balanceqty) into v_ywypt from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_ywypt := v_ywypt + v_adjustqty2;
--khjx
begin
SELECT nvl(b.CUSDEMANDQTY,0)
into v_khjx
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 1;
exception
when others then
v_khjx:= 0;
end;
--
/* select sum(a1.balanceqty) into v_khjx from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=1
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_khjx := v_khjx + v_adjustqty1;
--khpt
begin
SELECT nvl(b.CUSDEMANDQTY,0)
into v_khypt
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 2;
exception
when others then
v_khypt:= 0;
end;
--
/* select sum(a1.balanceqty) into v_khypt from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_khypt := v_khypt + v_adjustqty2;
--- qty1
begin
SELECT nvl(b.DEMANDQTY1,0)
into v_qty1
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
-- and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid);
exception
when others then
v_qty1:= 0;
end;
--
/* select sum(zcd.DEMANDQTY1) into v_qty1 from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
--- qty2
begin
SELECT nvl(b.DEMANDQTY2,0)
into v_qty2
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
-- and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid);
exception
when others then
v_qty2:= 0;
end;
--
/* select sum(zcd.DEMANDQTY2) into v_qty2 from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
--- qty3
begin
SELECT nvl(b.DEMANDQTY3,0)
into v_qty3
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
-- and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid);
exception
when others then
v_qty3:= 0;
end;
--
/* select sum(zcd.DEMANDQTY3) into v_qty3 from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_row_ztdomesticdemandaudit := ROW_ZTDOMESTICDEMANDAUDIT(months,
v_xilie, v_pinpai,v_jihuapinpai,v_prodcode,v_prodname,v_gbjx,v_gbpt,v_bmjx,
v_bmpt, v_qyjx,v_qupt, v_ywyjx, v_ywypt, v_khjx,v_khypt,v_qty1,v_qty2,
v_qty3);
pipe row(v_row_ztdomesticdemandaudit);
end loop;
commit;
return;
exception
when others then
v_mess := sqlerrm;
end F_TEST;
2,通过pipe管道输出到自己新建的type中,type中可以灵活定义输出的列
--type row
CREATE OR REPLACE TYPE "ROW_ZTDOMESTICDEMANDAUDIT" as object
(
months varchar2(32),
v_xilie varchar2(128),
v_pinpai varchar2(128),
v_jihuapinpai varchar2(128),
v_prodcode varchar2(32),
v_prodname varchar2(512),
v_gbjx number(16),
v_gbpt number(16),
v_bmjx number(16),
v_bmpt number(16),
v_qyjx number(16),
v_qupt number(16),
v_ywyjx number(16),
v_ywypt number(16),
v_khjx number(16),
v_khypt number(16),
v_qty1 number(16),
v_qty2 number(16),
v_qty3 number(16)
);
type table
CREATE OR REPLACE TYPE "TABLE_ZTDOMESTICDEMANDAUDIT" as table of ROW_ZTDOMESTICDEMANDAUDIT;
可以直接组合几个表中的数据,然后简单查询就ok了
select count(1) from table(F_ZTDOMESTICDEMANDAUDITS(null ,null ,null ,null ))
查询到的数据可以直接放到list中,显示或导出。
CREATE OR REPLACE FUNCTION "F_TEST"( p_areaid in number,
p_prodid in number,
p_year in number,
p_month in number)
return table_ztdomesticdemandaudit
/*
reportnames */
pipelined is
pragma autonomous_transaction;
v_row_ztdomesticdemandaudit ROW_ZTDOMESTICDEMANDAUDIT;
months varchar2(32);
v_xilie varchar2(128);
v_pinpai varchar2(128);
v_jihuapinpai varchar2(128);
v_prodcode varchar2(32);
v_prodname varchar2(512);
v_gbjx number(16) := 0;
v_gbpt number(16) := 0;
v_bmjx number(16) := 0;
v_bmpt number(16) := 0;
v_qyjx number(16) := 0;
v_qupt number(16) := 0;
v_ywyjx number(16) := 0;
v_ywypt number(16) := 0;
v_khjx number(16) := 0;
v_khypt number(16) := 0;
v_qty1 number(16);
v_qty2 number(16);
v_qty3 number(16);
v_mess varchar2(512) := '';
v_adjustqty1 number(16) := 0;
v_adjustqty2 number(16) := 0;
v_prodid number(16);
v_areaid number(16);
v_plancustomertype number(16);
---------------------------------------------------------
begin
for c1 in (select to_char(a.AUDITDATE, 'yyyy-mm') as months,
d.valuename as xl, --系列
pb.brandname AS pp,
dd.valuename as jhpp,
p.prodcode,
pl.prdn,
p.prodid,ba.areaid,a.plancustomertype
--a.DEMANDQTY1
from ztdomesticdemandaudit a,
product p,
dictionary d,
dictionary dd,
productlang pl,
productbrand pb,
businessarea ba
where 1 = 1
and a.prodid = p.prodid
and p.prodid = pl.prodid
and p.brandcode = pb.brandcode
and pl.languagecode = pb.languagecode
and pl.languagecode = 'cn'
and a.plancustomertype in (1, 2)
and a.areaid = ba.areaid
and p.ztprodseries = d.value
and d.type = 'ZTTyreSeries'
and d.languagecode = 'cn'
and p.ztplanbrand = dd.value(+)
and dd.type(+) = 'ZTPlanBrand'
and dd.languagecode(+) = 'cn'
and ba.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba.areaid)
connect by parentareaid = prior areaid)
-- and a.plancustomertype =
-- nvl(p_plancustomertype, a.plancustomertype)
and to_char(a.auditdate, 'yyyy') =
nvl(p_year, to_char(a.auditdate, 'yyyy'))
and to_char(a.auditdate, 'mm') =
nvl(p_month, to_char(a.auditdate, 'mm'))
and p.PRODID = nvl(p_prodid, p.PRODID)
order by a.prodid) loop
months := c1.months;
v_xilie := c1.xl;
v_pinpai := c1.pp;
v_jihuapinpai := c1.jhpp;
v_prodcode := c1.prodcode;
v_prodname := c1.prdn;
v_prodid := c1.prodid;
v_areaid :=c1.areaid;
v_plancustomertype :=c1.plancustomertype;
--v_qty1:=c1.DEMANDQTY1;
--adjustqty 1
if v_plancustomertype = 1 then
begin
select nvl(adjustqty, 0)
into v_adjustqty1
from ztdomesticdemandadjust zt,
ztdomesticdemand zc,
ztdomesticdemanddetail zcd
where zc.orgid = zt.orgid
and zc.partnerid = zt.partnerid
and zcd.prodid = zt.prodid
and to_char(zt.adjustdate, 'yyyy') =
nvl(to_char(months,'yyyy'), to_char(zt.adjustdate, 'yyyy'))
and to_char(zt.adjustdate, 'mm') =
nvl(to_char(months,'mm'), to_char(zt.adjustdate, 'mm'))
-- and zt.prodid = nvl(p_prodid, zt.prodid)
and zt.prodid=nvl(v_prodid,zt.prodid)
and zc.PLANCUSTYPE = 1;
exception
when others then
v_adjustqty1:= 0;
end;
elsif v_plancustomertype = 2 then
--adjustqty 2
begin
select nvl(adjustqty, 0)
into v_adjustqty2
from ztdomesticdemandadjust zt,
ztdomesticdemand zc,
ztdomesticdemanddetail zcd
where zc.orgid = zt.orgid
and zc.partnerid = zt.partnerid
and zcd.prodid = zt.prodid
and to_char(zt.adjustdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(zt.adjustdate, 'yyyy'))
and to_char(zt.adjustdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(zt.adjustdate, 'mm'))
-- and zt.prodid = nvl(p_prodid, zt.prodid)
and zt.prodid=nvl(v_prodid,zt.prodid)
and zc.PLANCUSTYPE = 2;
exception
when others then
v_adjustqty2:= 0;
end;
end if;
--gbjx
begin
select nvl(a1.balanceqty,0)
into v_gbjx
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and plancustomertype = 1
and ba1.grade = 2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_gbjx:= 0;
end;
v_gbjx := v_gbjx + v_adjustqty1;
--gbpt
begin
select nvl(a1.balanceqty,0)
into v_gbpt
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and plancustomertype = 2
and ba1.grade = 2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_gbpt:= 0;
end;
v_gbpt := v_gbpt + v_adjustqty2;
--bmjx
begin
select nvl(a1.balanceqty,0)
into v_bmjx
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and plancustomertype = 1
and ba1.grade = 3
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_bmjx:= 0;
end;
v_bmjx := v_bmjx + v_adjustqty1;
--bmpt
begin
select nvl(a1.balanceqty,0)
into v_bmpt
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and a1.plancustomertype = 2
and ba1.grade = 3
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_bmpt:= 0;
end;
v_bmpt := v_bmpt + v_adjustqty1;
--qyjx
begin
select nvl(a1.balanceqty,0)
into v_qyjx
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and a1.plancustomertype = 1
and ba1.grade = 4
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_qyjx:= 0;
end;
v_qyjx := v_qyjx + v_adjustqty1;
--qypt
begin
select nvl(a1.balanceqty,0)
into v_qupt
from ztdomesticdemandaudit a1, businessarea ba1, product prod
where a1.areaid = ba1.areaid
and a1.prodid = prod.prodid
and a1.plancustomertype = 2
and ba1.grade = 4
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(v_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and to_char(a1.auditdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a1.auditdate, 'mm'))
-- and prod.PRODID = nvl(p_prodid, prod.prodid)
and prod.prodid=nvl(v_prodid,prod.prodid);
exception
when others then
v_qupt:= 0;
end;
v_qupt := v_qupt + v_adjustqty2;
--ywyjx
begin
SELECT nvl(b.SALESBALANCEQTY,0)
into v_ywyjx
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 1;
exception
when others then
v_ywyjx:= 0;
end;
--
/* select sum(a1.balanceqty) into v_ywyjx from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=1
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_ywyjx := v_ywyjx + v_adjustqty1;
--ywypt
begin
SELECT nvl(b.SALESBALANCEQTY,0)
into v_ywypt
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 2;
exception
when others then
v_ywypt:= 0;
end;
--
/* select sum(a1.balanceqty) into v_ywypt from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_ywypt := v_ywypt + v_adjustqty2;
--khjx
begin
SELECT nvl(b.CUSDEMANDQTY,0)
into v_khjx
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 1;
exception
when others then
v_khjx:= 0;
end;
--
/* select sum(a1.balanceqty) into v_khjx from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=1
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_khjx := v_khjx + v_adjustqty1;
--khpt
begin
SELECT nvl(b.CUSDEMANDQTY,0)
into v_khypt
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid)
and c.ztplancustomertype = 2;
exception
when others then
v_khypt:= 0;
end;
--
/* select sum(a1.balanceqty) into v_khypt from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid and a1.plancustomertype=2
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_khypt := v_khypt + v_adjustqty2;
--- qty1
begin
SELECT nvl(b.DEMANDQTY1,0)
into v_qty1
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
-- and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid);
exception
when others then
v_qty1:= 0;
end;
--
/* select sum(zcd.DEMANDQTY1) into v_qty1 from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
--- qty2
begin
SELECT nvl(b.DEMANDQTY2,0)
into v_qty2
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
-- and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid);
exception
when others then
v_qty2:= 0;
end;
--
/* select sum(zcd.DEMANDQTY2) into v_qty2 from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
--- qty3
begin
SELECT nvl(b.DEMANDQTY3,0)
into v_qty3
FROM ztdomesticdemand a,
ztdomesticdemanddetail b,
organization c,
organization d,
product e,
productlang f,
productbrand g,
businessarea h,
orgrelationdetail i
WHERE 1 = 1
AND a.ztdomesticdemandid = b.ztdomesticdemandid
AND a.orgid = c.orgid
AND a.partnerid = d.orgid
AND f.languagecode = g.languagecode
AND e.brandcode = g.brandcode
AND e.prodid = f.prodid
AND b.prodid = e.prodid
AND c.orgid = i.targetorgid
AND h.areaid = i.areaid
AND f.languagecode = 'cn'
-- and i.globalpccode = 11
and i.sourceorgid = 100
and a.partnerid = 100
and i.areaid in (select areaid
from businessarea
start with areaid = nvl(v_areaid, i.areaid)
connect by parentareaid = prior areaid)
and to_char(a.submitdate, 'yyyy') =
nvl(to_char(to_date(months,'yyyy-MM'),'yyyy'), to_char(a.submitdate, 'yyyy'))
and to_char(a.submitdate, 'mm') =
nvl(to_char(to_date(months,'yyyy-MM'),'mm'), to_char(a.submitdate, 'mm'))
-- and b.PRODID = nvl(p_prodid, b.prodid)
and b.prodid=nvl(v_prodid,b.prodid);
exception
when others then
v_qty3:= 0;
end;
--
/* select sum(zcd.DEMANDQTY3) into v_qty3 from ztdomesticdemandaudit a1,businessarea ba1,product prod,ztdomesticdemand zc,ztdomesticdemanddetail zcd
where a1.areaid=ba1.areaid and zc.ztdomesticdemandid=zcd.ztdomesticdemandid and a1.prodid=zcd.prodid and a1.prodid=prod.prodid
and ba1.areaid in
(select areaid
from businessarea
start with areaid = nvl(p_areaid, ba1.areaid)
connect by parentareaid = prior areaid)
and a1.plancustomertype = nvl(p_plancustomertype, a1.plancustomertype)
and to_char(a1.auditdate, 'yyyy') = nvl(p_year,to_char(a1.auditdate, 'yyyy'))
and to_char(a1.auditdate, 'mm') = nvl(p_month,to_char(a1.auditdate, 'mm'))
and prod.PRODID=nvl(p_prodid,prod.prodid);*/
v_row_ztdomesticdemandaudit := ROW_ZTDOMESTICDEMANDAUDIT(months,
v_xilie, v_pinpai,v_jihuapinpai,v_prodcode,v_prodname,v_gbjx,v_gbpt,v_bmjx,
v_bmpt, v_qyjx,v_qupt, v_ywyjx, v_ywypt, v_khjx,v_khypt,v_qty1,v_qty2,
v_qty3);
pipe row(v_row_ztdomesticdemandaudit);
end loop;
commit;
return;
exception
when others then
v_mess := sqlerrm;
end F_TEST;
2,通过pipe管道输出到自己新建的type中,type中可以灵活定义输出的列
--type row
CREATE OR REPLACE TYPE "ROW_ZTDOMESTICDEMANDAUDIT" as object
(
months varchar2(32),
v_xilie varchar2(128),
v_pinpai varchar2(128),
v_jihuapinpai varchar2(128),
v_prodcode varchar2(32),
v_prodname varchar2(512),
v_gbjx number(16),
v_gbpt number(16),
v_bmjx number(16),
v_bmpt number(16),
v_qyjx number(16),
v_qupt number(16),
v_ywyjx number(16),
v_ywypt number(16),
v_khjx number(16),
v_khypt number(16),
v_qty1 number(16),
v_qty2 number(16),
v_qty3 number(16)
);
type table
CREATE OR REPLACE TYPE "TABLE_ZTDOMESTICDEMANDAUDIT" as table of ROW_ZTDOMESTICDEMANDAUDIT;
可以直接组合几个表中的数据,然后简单查询就ok了
select count(1) from table(F_ZTDOMESTICDEMANDAUDITS(null ,null ,null ,null ))
查询到的数据可以直接放到list中,显示或导出。
相关推荐
在实践中,SQL、T-SQL和PL-SQL都是关系数据库中的必备语言,但它们之间存在着一定的区别。SQL是关系数据库的标准语言,适用于各种关系数据库管理系统,而T-SQL和PL-SQL分别是SQL SERVER和Oracle的专有语言。T-SQL和...
PL/SQL是Oracle数据库系统中用于编写存储过程、函数、触发器等数据库编程的结构化查询语言,扩展了SQL的功能,使得数据库管理员和开发人员能够进行更复杂的数据库操作和管理。Allround Automation PL-SQL Developer...
PL-SQL,全称为Procedural Language/Structured Query Language,是Oracle数据库系统中的一种扩展的SQL语言,它结合了SQL的查询能力与编程语言的控制结构,使得开发者能够编写存储过程、函数、触发器等复杂数据库...
- 过程和函数是PL/SQL中的可重用代码单元,过程不返回值,而函数返回一个值。它们可以接受参数,方便模块化编程。 7. 程序包的创建与应用: - 程序包是将相关的过程和函数组合在一起的高级结构,提高了代码的封装...
PL-SQL,全称为Procedural Language/Structured Query Language,是Oracle数据库系统中用于扩展SQL功能的一种编程语言。它是SQL的面向过程版本,允许开发者在处理数据时编写复杂的逻辑和控制流程,使得数据库操作...
二、PL-SQL函数和过程 1. **内置函数**:Oracle提供了一系列内置函数,如数学函数、字符串函数、日期时间函数等,方便进行数据处理。 2. **自定义函数**:用户可以创建自己的函数,接收参数,执行特定逻辑,并返回...
下面我们将详细探讨Oracle PL-SQL与Hadoop Hive、Phoenix中常用的对应函数。 1. **日期函数**: - Oracle PL-SQL中的日期函数如`SYSDATE`获取当前系统日期,`ADD_MONTHS`添加月份,`EXTRACT`提取日期部分等。在...
《PL-SQL用户指南与参考》是一份详尽的中文PDF文档,总计12章,包含312页,旨在帮助读者深入理解并熟练掌握Oracle数据库中的PL/SQL编程语言。PL/SQL,即Procedural Language/Structured Query Language,是Oracle...
在【标题】"PL-SQL.zip"中,我们看到这是一个与PL-SQL相关的压缩文件。通常,这样的压缩包可能包含用于学习、开发或管理Oracle数据库的资源,比如文档、教程、密钥、安装程序等。"PL-SQL.zip里有密钥"可能指的是该...
Oracle PL-SQL(Procedural Language/Structured Query Language)是Oracle数据库系统中的一种编程语言,它结合了SQL的查询功能和传统的过程式编程语言的特点,为数据库开发提供了强大的支持。对于初学者而言,掌握...
PL-SQL可以直接操作Oracle数据库中的表、视图、索引等对象,进行增删改查操作,并且可以通过动态SQL执行未在编写时已知的SQL语句。 九、面向对象特性 Oracle数据库从9i版本开始引入了面向对象特性,PL-SQL可以创建...
在PL-SQL中,块的概念非常关键,它可以是匿名块(直接在SQL*Plus或其他环境执行)或命名块(如过程、函数、包)。 PL-SQL的控制结构是其强大之处。流程控制语句如IF-THEN-ELSIF-ELSE、CASE、FOR循环和WHILE循环使得...
内有文件: Oracle PL-SQL入门之慨述.doc Oracle PL-SQL语言基础.doc ORACLE 数据库开发经验总结.doc Oracle9i PL-SQL编程的经验小结.doc ORACLE函数大全.doc Oracle中使用PL-SQL操作...PL-SQL单行函数和组函数详解.doc
在PL-SQL中,你可以编写复杂的数据库应用程序,执行数据查询、更新、删除等操作,并且能够创建和管理存储过程。 PL-SQL的基础操作主要包括以下几个方面: 1. **查询**:使用SELECT语句进行数据查询。例如,你可以...
在Oracle环境中,PL/SQL可以用来创建存储过程、函数、触发器、游标,以及进行异常处理,极大地提高了数据库应用的效率和灵活性。 以下是PL-SQL的一些关键知识点: 1. **基础语法**:包括声明变量、常量、游标、...
- **数据查看和操作**:除了编写SQL,PL-SQL Developer还提供数据浏览和操作功能,你可以直接在IDE内查看表中的数据,执行DML操作(INSERT, UPDATE, DELETE)。 - **许可证管理**:软件的注册文件和许可证管理是...
Oracle PL-SQL 与 Hadoop Hive 和 Phoenix 是两种不同的数据处理和存储系统,它们各自拥有独特的函数库,但在数据操作中存在一些相似的功能。本文将详细介绍 Oracle PL-SQL 中的一些常见函数,以及它们在 Hadoop ...
Oracle PL-SQL是一种强大的数据库编程语言,用于在Oracle数据库环境中创建和管理复杂的业务逻辑和数据处理任务。在“Oracle PL-SQL 中联模拟笔试题”中,你可以期待一系列旨在测试和提升你对PL-SQL理解的题目。这些...