1

我正在使用 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 字段仍然为空——可能是什么问题?我尝试使用 SELF.time_completed 无济于事,并且过程中的所有其他变量都被适当地引用。这是否与这个变量来自超类型的事实有关?或者可能是我通过取消引用的指针调用该过程?任何帮助深表感谢。

4

1 回答 1

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;
/
于 2012-12-08T20:22:24.463 回答