PL / SQL ORA-00933:SQL命令未正确结束

时间:2013-12-06 02:57:31

标签: sql oracle stored-procedures plsql

参考此Post' AS'不支持,使用SQL命令实现我的替换语法是什么?

CREATE OR REPLACE PROCEDURE "LCAccountSP" (
    xReceiptType IN VARCHAR2,
    xManual IN VARCHAR2,
    xRCO IN VARCHAR2,
    xMuncID IN VA) AS
BEGIN
    CASE        
        WHEN xReceiptType = 'ROR' THEN 
            SELECT xAccount, xCount, xAmount 
            FROM (
                SELECT 
                    b.ACCT_CODE AS xAccount, 
                    COUNT(*) AS xCount, 
                    SUM(b.ROR_TOTAL_PAID) as xAmount 
                FROM tbl_tax_payment aa
                    INNER JOIN tbl_revenue_official_receipt b
                        ON aa.TPAY_RECEIPT_NO = b.TPAY_RECEIPT_NO 
                WHERE
                    aa.RECEIPT_TYPE = xReceiptType
                    AND aa.RECEIPT_MODE = xManual 
                    AND aa.LOC_NO IS NULL 
                    AND aa.RCO_CODE = xRCO 
                    AND aa.MUNC_ID = xMuncID 
                GROUP BY xAccount
            ) AS xAccount;

        WHEN xReceiptType = 'OR' THEN 
            SELECT xAccount, xCount, xAmount 
            FROM (
                SELECT b.ACCT_CODE AS xAccount,
                    COUNT(*) AS xCount,
                    SUM(b.OR_TOTAL_PAID) as xAmount  
                FROM tbl_tax_payment aa 
                    INNER JOIN tbl_official_receipt b
                    ON aa.TPAY_RECEIPT_NO = b.TPAY_RECEIPT_NO 
                WHERE aa.RECEIPT_TYPE = xReceiptType 
                    AND aa.RECEIPT_MODE = xManual 
                    AND aa.LOC_NO IS NULL 
                    AND aa.RCO_CODE = xRCO 
                    AND aa.MUNC_ID = xMuncID 
                GROUP BY xAccount
            ) AS xAccount;

        WHEN xReceiptType = 'AR' THEN 

            SELECT xAccount, xCount, xAmount
            FROM (
                SELECT b.ACCT_CODE AS xAccount,
                    COUNT(*) AS xCount,
                    SUM(b.AR_TOTAL_PAID) as xAmount  
                FROM tbl_tax_payment aa
                    INNER JOIN tbl_ack_receipt b 
                        ON aa.TPAY_RECEIPT_NO = b.TPAY_RECEIPT_NO 
                WHERE aa.RECEIPT_TYPE = xReceiptType 
                    AND aa.RECEIPT_MODE = xManual 
                    AND aa.LOC_NO IS NULL 
                    AND aa.RCO_CODE = xRCO 
                    AND aa.MUNC_ID = xMuncID 
                GROUP BY xAccount
            ) AS xAccount;
    END CASE;
END;

1 个答案:

答案 0 :(得分:0)

在定义表的假名时,只需要删除AS。使用AS定义列的假名是正常的。请查看此示例http://sqlfiddle.com/#!4/d41d8/21775

更新也将过程xMuncID IN VA的参数更正为xMuncID IN VARCHAR2

尝试调用此代码:

CREATE OR REPLACE PROCEDURE "LCAccountSP" (
    xReceiptType IN VARCHAR2,
    xManual IN VARCHAR2,
    xRCO IN VARCHAR2,
    xMuncID IN VARCHAR2)
AS
    -- please check that datatypes is suite for your needs
    v_xAccount varchar2(100);
    v_xCount number;
    v_xAmount number;
BEGIN
    CASE        
        WHEN xReceiptType = 'ROR' THEN 
            SELECT xAccount, xCount, xAmount 
            INTO v_xAccount, v_xCount, v_xAmount 
            FROM (
                SELECT 
                    b.ACCT_CODE AS xAccount, 
                    COUNT(*) AS xCount, 
                    SUM(b.ROR_TOTAL_PAID) as xAmount 
                FROM tbl_tax_payment aa
                    INNER JOIN tbl_revenue_official_receipt b
                        ON aa.TPAY_RECEIPT_NO = b.TPAY_RECEIPT_NO 
                WHERE
                    aa.RECEIPT_TYPE = xReceiptType
                    AND aa.RECEIPT_MODE = xManual 
                    AND aa.LOC_NO IS NULL 
                    AND aa.RCO_CODE = xRCO 
                    AND aa.MUNC_ID = xMuncID 
                GROUP BY b.ACCT_CODE
            ) xAccount;

        WHEN xReceiptType = 'OR' THEN 
            SELECT xAccount, xCount, xAmount 
            INTO v_xAccount, v_xCount, v_xAmount 
            FROM (
                SELECT b.ACCT_CODE AS xAccount,
                    COUNT(*) AS xCount,
                    SUM(b.OR_TOTAL_PAID) as xAmount  
                FROM tbl_tax_payment aa 
                    INNER JOIN tbl_official_receipt b
                    ON aa.TPAY_RECEIPT_NO = b.TPAY_RECEIPT_NO 
                WHERE aa.RECEIPT_TYPE = xReceiptType 
                    AND aa.RECEIPT_MODE = xManual 
                    AND aa.LOC_NO IS NULL 
                    AND aa.RCO_CODE = xRCO 
                    AND aa.MUNC_ID = xMuncID 
                GROUP BY b.ACCT_CODE
            ) xAccount;

        WHEN xReceiptType = 'AR' THEN 

            SELECT xAccount, xCount, xAmount
            INTO v_xAccount, v_xCount, v_xAmount 
            FROM (
                SELECT b.ACCT_CODE AS xAccount,
                    COUNT(*) AS xCount,
                    SUM(b.AR_TOTAL_PAID) as xAmount  
                FROM tbl_tax_payment aa
                    INNER JOIN tbl_ack_receipt b 
                        ON aa.TPAY_RECEIPT_NO = b.TPAY_RECEIPT_NO 
                WHERE aa.RECEIPT_TYPE = xReceiptType 
                    AND aa.RECEIPT_MODE = xManual 
                    AND aa.LOC_NO IS NULL 
                    AND aa.RCO_CODE = xRCO 
                    AND aa.MUNC_ID = xMuncID 
                GROUP BY b.ACCT_CODE
            ) xAccount;
    END CASE;
END;