0

在这里我创建了一个存储过程,但它在这里不工作是语法有问题任何人都可以帮助

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; 
4

1 回答 1

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);

等等

如果您的想法是只想将该结果集返回给调用者,则可以返回一个 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;
于 2013-02-04T11:16:38.677 回答