使用Type和Table Dependencies创建或替换TYPE

时间:2013-05-20 17:44:12

标签: oracle oop plsql

在提交此问题之前,我已经检查了有关此主题的Oracle文档: Using CREATE OR REPLACE TYPE with Type and Table Dependencies

但仍然没有解决我的错误。

我创建了一些对象类型:

CREATE OR REPLACE TYPE SchoolMember AS OBJECT (
    ...
) NOT FINAL;
/

CREATE OR REPLACE TYPE Teacher UNDER SchoolMember (
   ...
);
/

CREATE OR REPLACE TYPE Curse AS OBJECT (
   ...
   refTeacher REF Teacher,
   ...
);
/

假设我要修改添加构造函数的Teacher对象类型:

CREATE OR REPLACE TYPE Teacher UNDER SchoolMember (
   ...
   CONSTRUCTOR FUNCTION Teacher(...) RETURN SELF AS RESULT
);
/

CREATE OR REPLACE TYPE BODY Teacher AS
...
END;
/

我得到 ORA-02303:不能删除或替换类型或表依赖的类型,因为教师类型在Curse对象类型本身中使用。

在修改继承的对象类型(本例中为Teacher)时,应该在哪里放置FORCE选项? 我尝试了几种方法,但没有一种方法可以工作:

CREATE OR REPLACE TYPE Teacher FORCE UNDER SchoolMember

CREATE OR REPLACE TYPE Teacher UNDER SchoolMember FORCE

但是ORA-02303错误仍然存​​在

2 个答案:

答案 0 :(得分:3)

我无法完全重现您的问题。

原始对象

SQL> CREATE OR REPLACE TYPE SchoolMember AS OBJECT (a number) NOT FINAL;
  2  /

Type created.

SQL> CREATE OR REPLACE TYPE Teacher UNDER SchoolMember (b number);
  2  /

Type created.

SQL> CREATE OR REPLACE TYPE Curse AS OBJECT (refTeacher REF Teacher);
  2  /

Type created.

无FORCE失败

SQL> CREATE OR REPLACE TYPE Teacher UNDER SchoolMember (
  2     b number,
  3     CONSTRUCTOR FUNCTION Teacher RETURN SELF AS RESULT
  4  );
  5  /
CREATE OR REPLACE TYPE Teacher UNDER SchoolMember (
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents

使用FORCE工作

SQL> CREATE OR REPLACE TYPE Teacher FORCE UNDER SchoolMember (
  2     b number,
  3     CONSTRUCTOR FUNCTION Teacher RETURN SELF AS RESULT
  4  );
  5  /

Type created.

<强>更新

{11}增加了FORCE的{​​{1}}选项。您可以在this 11gR2语法图中看到它,但不能在this 11gR1图表中看到它。

在您的情况下,您需要在重新创建之前删除该类型。

CREATE TYPE

答案 1 :(得分:0)

使用force选项删除类型并执行代码。它会起作用

DROP TYPE Teacher VALIDATE FORCE;

SQL> CREATE OR REPLACE TYPE Teacher UNDER SchoolMember (
       b number,
       CONSTRUCTOR FUNCTION Teacher RETURN SELF AS RESULT
    );

已创建类型。