0

我想取回以下 sp 的参考光标。但它不起作用..没有得到任何记录..所以请帮助我。

DATA_INPUTLIST - 它是两个变量(mtn,mtnEffDate)的集合类型 DATA_RESULTLIST - 它也是 3 个变量(id,effDate,mtn)的集合类型

 CREATE OR REPLACE PROCEDURE proc1 (
       pCustId  IN  NUMBER,
       pAcctNo    IN    NUMBER,
       pSearchCriteria    IN    DATA_INPUTLIST,
       pRecordSet OUT SYS_REFCURSOR,
       out_error_code   OUT   NUMBER,
       out_error_message   OUT   VARCHAR2
    ) AS

        --Variables
        v_SUN_DATE DATE := TO_DATE('01/15/2011', 'mm/dd/yyyy');
        vCount    NUMBER := 0;
        v_mtn NUM

BER;
    v_mtn_eff_date DATE;
    cMtnPricePlanInfo DATA_RESULTLIST;

BEGIN

    SELECT COUNT(*) INTO vCount FROM TABLE (pSearchCriteria);

    FOR i IN 1..vCount LOOP

        SELECT MTN, TO_DATE(MTN_EFF_DATE, 'mm/dd/yyyy') into v_mtn, v_mtn_eff_date 
        FROM TABLE (pSearchCriteria) 
        WHERE 
        ROWNUM = i; 

        SELECT 
            A.PPLAN_ID, A.EFF_DATE, A.MTN INTO cMtnPricePlanInfo(i).PPLAN_ID, cMtnPricePlanInfo(i).EFF_DATE, cMtnPricePlanInfo(i).MTN
        FROM CUST_ACCT_LINE_PPLAN A, CUST_ACCT_LINE_PPLAN_HIST B
        WHERE
            A.CUST_ID  = pCustId
            AND A.ACCT_NO    = pAcctNo
            AND A.MTN = v_mtn
            AND A.MTN_EFF_DATE = v_mtn_eff_date
            AND A.EFF_DATE >= 
                (SELECT MAX(EFF_DATE) FROM CUST_ACCT_LINE_PPLAN_HIST C
                WHERE
                    C.CUST_ID  = pCustId
                    AND C.ACCT_NO    = pAcctNo
                    AND C.MTN = v_mtn
                    AND C.MTN_EFF_DATE = v_mtn_eff_date
                    AND C.EFF_DATE <= v_SUN_DATE)
            AND A.CUST_ID = B.CUST_ID
            AND A.ACCT_NO = B.ACCT_NO
            AND A.MTN = B.MTN
            AND A.MTN_EFF_DATE = B.MTN_EFF_DATE
            AND A.PPLAN_ID = B.PPLAN_ID;

    END LOOP;
       OPEN pRecordSet FOR
            SELECT * FROM TABLE (cMtnPricePlanInfo);

END;
/
4

1 回答 1

1

对我来说突出的第一件事是:

    SELECT MTN, TO_DATE(MTN_EFF_DATE, 'mm/dd/yyyy') into v_mtn, v_mtn_eff_date 
    FROM TABLE (pSearchCriteria) 
    WHERE 
    ROWNUM = i; 

对于i大于 1,这不会返回任何内容。至于原因,请看这个问题。事实上,因为你使用的是 ,如果大于或等于 2 SELECT ... INTO ...,你会得到一个no data found错误。i

您不需要 SQL 查询来从 PL/SQL 集合中获取一些值。尝试将此查询替换为

    v_mtn := pSearchCriteria(i).MTN;
    v_mtn_eff_date := TO_DATE(pSearchCriteria(i).MTN_EFF_DATE, 'mm/dd/yyyy');

I don't have your tables nor the data in them so I can't be sure why you're getting no data. I can only hazard at some obvious suggestions: is vCount zero? If you put suitable values for v_mtn and v_mtn_eff_date and run your query on its own, separate from this stored procedure, does it return any rows?

于 2012-09-29T22:15:03.843 回答