请帮我怎么做
CREATE OR REPLACE PROCEDURE CTCSIS.SP_RptSalesPeriodic_Chathu
(
intLocIDxx in integer, strFromDate in varchar2, strToDate in varchar2,strSessionId in Varchar2
)
as
Cursor C1 is
SElECT Distinct
i.stritmitemnarration As FAMILY,
ctcsis.Fn_GetBrandFamily(intSalSalesSku) AS MAINFAMILY,
tab4.strlocnarration As LOCATION,
tab3.intsallocation As LOCATION_ID,
TO_DATE(tab3.strsaleffectdate,'MM/DD/YYYY') As DATE_RANGE,
SUM(tab3.dclsalsalestarget) AS TARGET,
((SELECT SUM(tab1.dclinvdtlqty)
FROM (select * from ctcsis.tblinvinvoicedetail d where d.intinvdistributerid=301) tab1
INNER JOIN (select * from ctcsis.tblinvinvoiceheader h where h.intinvdistributerid=301) tab2
ON tab1.intinvdtlheadcode=tab2.intinvinvoiceid
WHERE (tab1.intinvdtlsku=tab3.intsalsalessku) AND
TO_DATE(tab2.strinvinvoicedate,'MM/DD/YYYY') BETWEEN TO_DATE(strFromDate,'MM-DD-YYYY')
AND TO_DATE(strToDate,'MM-DD-YYYY')
AND tab2.intinvcovloc= tab3.intsallocation)) AS ACTUAL,
ROUND((((SELECT SUM(tab1.dclinvdtlqty)
FROM (select * from ctcsis.tblinvinvoicedetail d where d.intinvdistributerid=301) tab1
INNER JOIN (select * from ctcsis.tblinvinvoiceheader h where h.intinvdistributerid=301) tab2
ON tab1.intinvdtlheadcode=tab2.intinvinvoiceid
WHERE (tab1.intinvdtlsku=tab3.intsalsalessku) AND
TO_DATE(tab2.strinvinvoicedate,'MM/DD/YYYY') BETWEEN TO_DATE(strFromDate,'MM-DD-YYYY')
AND TO_DATE(strToDate,'MM-DD-YYYY')
AND tab2.intinvcovloc= tab3.intsallocation)) -
(SUM(tab3.dclsalsalestarget)))*100/ (SUM(tab3.dclsalsalestarget)+ 0.01),2) As "PERC",
strsessionid AS SessionNo
FROM (select * from ctcsis.tblsalsalestarget t where t.intsaldistributerid=301
and t.strsalsalesdesc='test'and t.intsalsalesperiod=501
and t.intsalsalesday in (12,13)) tab3
INNER JOIN ctcsis.tblitmitemmaster i
ON i.intitmid=tab3.intsalsalessku
INNER JOIN (select * from ctcsis.tblloclocations l where l.intlocdistributerid=301) tab4
ON tab4.intlocid=tab3.intsallocation
WHERE
(i.bititmactive = 1)
And
tab3.intsallocation=intLocIDxx //Here I want to pass multiple parameters using IN
答案 0 :(得分:1)
Oracle提供了几种传递集合的类型,例如associative arrays, nested tables, or VARRAYS。
这是一个使用嵌套的整数表(t_Ints
)的简单示例,您需要将其用作intLocIDxx
参数的类型:
给出一张表:
CREATE TABLE Foo
(
ID INT,
Name VARCHAR2(50)
);
为参数集创建了一个嵌套类型:
CREATE TYPE t_Ints IS TABLE OF INT;
然后,在proc中,将类型作为输入参数传递,然后使用table()
函数连接到它。请注意,因为嵌套类型是一个简单的原始INT,所以伪列COLUMN_VALUE
被用作'值'列名:
CREATE OR REPLACE PROCEDURE GetFoos(
whichInts IN t_Ints,
results OUT sys_refcursor)
AS BEGIN
OPEN results FOR
SELECT * FROM FOOS f
INNER JOIN table( whichInts ) wi
on f.ID = wi.COLUMN_VALUE
END;