oracle 使用类型和表依赖项创建或替换类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16655148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:02:53  来源:igfitidea点击:

CREATE OR REPLACE TYPE with Type and Table Dependencies

oracleoopplsql

提问by rodrunner

Before submitting this question I've checked the Oracle docs about this subject: Using CREATE OR REPLACE TYPE with Type and Table Dependencies

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

but still don't get my error solved.

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

I've created some object types:

我创建了一些对象类型:

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,
   ...
);
/

Let's say I want to modify the Teacher object type adding a constructor:

假设我想修改教师对象类型,添加一个构造函数:

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

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

I get the ORA-02303: cannot drop or replace a type with type or table dependentsbecause the Teacher type is used in the Curse object type itself.

我得到 ORA-02303:无法删除或替换类型或表依赖项,因为教师类型用于 Curse 对象类型本身。

Where should I place the FORCE option when modifiying an inherited object type (Teacher in this case)? I've tried several ways, but none of them working:

在修改继承的对象类型(在这种情况下为教师)时,我应该在哪里放置 FORCE 选项?我尝试了几种方法,但都没有奏效:

CREATE OR REPLACE TYPE Teacher FORCE UNDER SchoolMember

or

或者

CREATE OR REPLACE TYPE Teacher UNDER SchoolMember FORCE

But the ORA-02303 error is still there

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

回答by Jon Heller

I cannot exactly reproduce your issue.

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

Original Objects

原始对象

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.

Create without FORCE fails

没有 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

Create with FORCE works

用力创作作品

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

Type created.


Update

更新

The FORCEoption for CREATE TYPEwas added in 11gR2. You can see it in this11gR2 syntax diagram, but not in this11gR1 diagram.

FORCE选项CREATE TYPE在11gR2的加入。您可以在这个11gR2 语法图中看到它,但在这个11gR1 图中看不到。

In your case, you will need to drop the type before you recreate it.

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

SQL> DROP TYPE Teacher VALIDATE;

Type dropped.

回答by Ravi

Drop the type with force option and execute your code. It will work

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

DROP TYPE Teacher VALIDATE FORCE;

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

Type created.

类型已创建。