2013-02-04 36 views
0

在這裏,我創建了一個存儲過程,但它不工作 這裏的東西是錯誤的語法,任何人都可以幫助我在甲骨文寫這個存儲過程9i中的不正確的,我需要正確的語法

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

嘗試運行它。如果錯誤,Oracle將打印一個'ORA - #####'錯誤代碼和錯誤描述以及可能的行號以幫助識別問題。 –

回答

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; 
相關問題