你不能在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;
嘗試運行它。如果錯誤,Oracle將打印一個'ORA - #####'錯誤代碼和錯誤描述以及可能的行號以幫助識別問題。 –