在Oracle PL / SQL成员过程中持续更改SELF的问题

时间:2012-12-05 05:26:27

标签: oracle plsql

我正在使用Oracle中的对象关系功能,并且无法持续更改成员过程中发生的对象。首先,我有一个抽象的超级类型:

CREATE TYPE fantasy_action AS OBJECT (
action_id      NUMBER,
time_completed DATE,
NOT INSTANTIABLE MEMBER PROCEDURE execute(SELF IN OUT NOCOPY fantasy_action)
NOT INSTANTIABLE NOT FINAL;

这是我的一个类型声明的一部分(也创建了相应的表):

CREATE TYPE fantasy_trade UNDER fantasy_action (
...[other variables]...
OVERRIDING MEMBER PROCEDURE execute(SELF IN OUT NOCOPY fantasy_trade));

我遇到的问题是成员程序的这一部分:

CREATE OR REPLACE TYPE BODY fantasy_trade AS
     OVERRIDING MEMBER PROCEDURE execute( SELF IN OUT NOCOPY fantasy_trade ) IS
     current_week NUMBER;
     player1_plays NUMBER;
     player2_plays NUMBER;
  BEGIN
     ...
     time_completed := current_date;
     ...
  END;
END;

最后,我调用该过程的方式是通过一个简单的PL / SQL循环:

DECLARE
   action fantasy_action;
  BEGIN
     FOR x IN (SELECT DEREF(action) as action FROM fantasy_scheduledaction WHERE time <= current_date AND DEREF(action).time_completed is null) LOOP
     x.action.execute();
END LOOP;
END;

即使在验证过程的其余部分通过后,time_completed字段仍为null - 可能是什么问题?我尝试过使用SELF.time_completed无效,程序中的所有其他变量都是适当的引用。这个变量来自超类型的事实是否与此有关?或者可能是我通过解除引用的指针调用该过程?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

尝试使用UTL_REF.UPDATE_OBJECT:

DECLARE
    action fantasy_action;
BEGIN
    FOR x IN
    (
        SELECT DEREF(action) as action_deref, action action_ref
        FROM fantasy_scheduledaction
        WHERE time <= current_date
            AND DEREF(action).time_completed is null
    ) LOOP
        x.action_deref.execute();
        utl_ref.update_object(x.action_ref, x.action_deref);
    END LOOP;
END;
/