这里我创建了一个存储过程,但它无法正常工作 这里的语法是错误的,任何人都可以提供帮助
CREATE OR REPLACE PROCEDURE MISSALESVSCOLLECTION
(
FROMDATE IN DATE,
TODATE IN DATE
)
AS
BEGIN
SELECT SUM(TBLORDERSTYLE.NQTY * TBLORDERSTYLE.NUNITPRICE/ 1000) AS TOTAL, TBLORDER.NPAYMODE,
(SELECT SUM(NEXPAMOUNT) FROM TBLEXPLC WHERE DINVDATE BETWEEN TO_DATE(FROMDATE) AND TO_DATE(TODATE)
AND (CEXPLCNO LIKE '%TT%' OR CEXPLCNO LIKE '%SC%')
) AS TT,
(SELECT SUM(NEXPAMOUNT) FROM TBLEXPLC WHERE DINVDATE BETWEEN TO_DATE(FROMDATE) AND TO_DATE(TODATE)
AND (CEXPLCNO NOT LIKE '%TT%' OR CEXPLCNO NOT LIKE '%SC%' OR CEXPLCNO NOT LIKE '%MR#%')
) AS LC,
(SELECT SUM(TBLORDERSTYLE.NQTY * TBLORDERSTYLE.NUNITPRICE/ 1000) FROM TBLORDER
INNER JOIN
TBLORDERSTYLE
ON
TBLORDER.CORDERNO = TBLORDERSTYLE.CORDERNO
WHERE TBLORDER.NPAYMODE = '3'
AND TBLORDER.CLCNO LIKE '%MR#%'
AND TBLORDER.DPICONFIRMDATE BETWEEN TO_DATE(FROMDATE) AND TO_DATE(TODATE)
)AS CASH
FROM TBLORDER
INNER JOIN
TBLORDERSTYLE
ON
TBLORDER.CORDERNO = TBLORDERSTYLE.CORDERNO AND
TBLORDER.NPOSTFLAG = '1' AND
TBLORDER.DPICONFIRMDATE BETWEEN TO_DATE(FROMDATE) AND TO_DATE(TODATE)
GROUP BY TBLORDER.NPAYMODE
END;
答案 0 :(得分:1)
你不能在PL / SQL中选择一个结果集。你必须用它做点什么。如果您有多行,则需要使用for a in (your sql)
将该选项括起来。即在你的情况下:
create or replace procedure missalesvscollection(fromdate in date, todate in date)
as
begin
for r_row in (select sum(tblorderstyle.nqty * tblorderstyle.nunitprice / 1000) as total,
tblorder.npaymode,
(select sum(nexpamount)
from tblexplc
where dinvdate between to_date(fromdate) and to_date(todate)
and (cexplcno like '%TT%' or cexplcno like '%SC%')) as tt,
(select sum(nexpamount)
from tblexplc
where dinvdate between to_date(fromdate) and to_date(todate)
and (cexplcno not like '%TT%' or cexplcno not like '%SC%' or
cexplcno not like '%MR#%')) as lc,
(select sum(tblorderstyle.nqty * tblorderstyle.nunitprice / 1000)
from tblorder
inner join tblorderstyle
on tblorder.corderno = tblorderstyle.corderno
where tblorder.npaymode = '3'
and tblorder.clcno like '%MR#%'
and tblorder.dpiconfirmdate between to_date(fromdate) and to_date(todate)) as cash
from tblorder
inner join tblorderstyle
on tblorder.corderno = tblorderstyle.corderno
and tblorder.npostflag = '1'
and tblorder.dpiconfirmdate between to_date(fromdate) and to_date(todate)
group by tblorder.npaymode)
loop
-- do something here.
end loop;
end;
在该循环中,您可以根据需要进行处理。如果您只想打印列,可以使用DBMS_OUTPUT
,如:
dbms_output.put_line('total = ' || r_row.total);
dbms_output.put_line('npaymode= ' || r_row.npaymode);
等
如果您的想法是只想将结果集返回给调用者,则可以返回引用光标。
即:
create or replace function missalesvscollection(fromdate in date, todate in date)
return sys_refcursor
as
v_rc sys_refcursor;
begin
open v_rc
for
select sum(tblorderstyle.nqty * tblorderstyle.nunitprice / 1000) as total,
tblorder.npaymode,
(select sum(nexpamount)
from tblexplc
where dinvdate between to_date(fromdate) and to_date(todate)
and (cexplcno like '%TT%' or cexplcno like '%SC%')) as tt,
(select sum(nexpamount)
from tblexplc
where dinvdate between to_date(fromdate) and to_date(todate)
and (cexplcno not like '%TT%' or cexplcno not like '%SC%' or
cexplcno not like '%MR#%')) as lc,
(select sum(tblorderstyle.nqty * tblorderstyle.nunitprice / 1000)
from tblorder
inner join tblorderstyle
on tblorder.corderno = tblorderstyle.corderno
where tblorder.npaymode = '3'
and tblorder.clcno like '%MR#%'
and tblorder.dpiconfirmdate between to_date(fromdate) and to_date(todate)) as cash
from tblorder
inner join tblorderstyle
on tblorder.corderno = tblorderstyle.corderno
and tblorder.npostflag = '1'
and tblorder.dpiconfirmdate between to_date(fromdate) and to_date(todate)
group by tblorder.npaymode;
return v_rc;
end;