带有Oracle Objects和For循环的PLS-00382

时间:2016-05-11 19:23:30

标签: oracle collections oracle11g user-defined-types

下面我正在尝试对我的集合进行分组,然后使用数据调用其他函数/存储过程。由于某种原因,我无法弄清楚为什么错误是 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;

1 个答案:

答案 0 :(得分:1)

我认为您的错误是假设Recippayment循环中返回SELECT * FROM TABLE(Listofpayments)的行是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类型。