PLS-00382 与 Oracle 对象和 For 循环

PLS-00382 with Oracle Objects and For loop

下面我尝试对我的集合进行分组,并使用数据对其他 functions/stored 过程进行一些调用。出于某种原因,我无法弄清楚为什么错误说 PLS-00382 表达式类型错误。我没有包括调用,但如果我尝试将 Recippayment 分配给 Oupayment,我会遇到同样的问题。任何帮助将不胜感激。

CREATE OR REPLACE TYPE Over_Under_Payment AS OBJECT
(
    Demoid            NUMBER,
    Paymentamount     NUMBER,
    Month     DATE
)

CREATE OR REPLACE TYPE OVER_UNDER_PAYMENT_LIST as table of OVER_UNDER_PAYMENT


PROCEDURE Pass_Payments(Listofpayments IN Over_Under_Payment_List) IS

    Oupayment Over_Under_Payment;

BEGIN
    FOR Recipient IN (SELECT Demoid
                      FROM   TABLE(CAST(Listofpayments AS Over_Under_Payment_List))
                      GROUP  BY Demoid) LOOP
        FOR Recippayment IN (SELECT *
                             FROM   TABLE(CAST(Listofpayments AS Over_Under_Payment_List))
                             WHERE  Demoid = Recipient.Demoid) LOOP
            Oupayment := Recippayment;
        END LOOP;
    END LOOP;
END;

我认为你的错误是假设在你的 SELECT * FROM TABLE(Listofpayments) 循环中返回到 Recippayment 的行是一个 Over_Under_Payment 对象。

Recippayment 的实际类型是 record variable of the row type returned by the cursor,换句话说,与您的 Over_Under_Payment 类型具有相同字段名称的记录。

使该过程起作用的一种方法是在内循环中重建您的对象:

    FOR Recippayment IN (SELECT Over_Under_Payment(Demoid, Paymentamount, Month) AS Payment
                         FROM   TABLE(CAST(Listofpayments AS Over_Under_Payment_List))
                         WHERE  Demoid = Recipient.Demoid) LOOP
        Oupayment := Recippayment.Payment;
    END LOOP;

这样,Recippayment 的类型是一种记录类型,其中有一个类型为 Over_Under_Payment 的字段,我选择将其命名为 Payment。在循环体中,我们从记录中取出对象。

顺便说一下,您可以将 CAST(Listofpayments AS Over_Under_Payment_List) 替换为 Over_Under_Payment_List,因为 Listofpayments 已经是 Over_Under_Payment_List.

类型