您不能只选择 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);
等等
如果您的想法是只想将该结果集返回给调用者,则可以返回一个 ref 游标。
即类似的东西:
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;