如何检查类型的依赖顺序以删除它们并替换/修改初始类型?

发布于 2024-08-28 18:38:38 字数 283 浏览 5 评论 0原文

我尝试使用以下代码修改类型,但它给出了错误代码:“ORA-02303”。我对 Oracle 或 PL/SQL 不太了解,但我需要解决这个问题;所以我希望得到任何进一步的帮助。

提前致谢。该代码只是一个示例。但话又说回来,我需要先检查它的依赖者。

create or replace type A as object (
  x_ number, 
  y_ varchar2(10),
  member procedure to_upper
);
/

I tried to modify a type using the following code and it gave me the error code: 'ORA-02303'. I don't know much about Oracle or PL/SQL but I need to solve this; so I'd appreciate any further help with this.

Thanks in advance. The code is just an example. But then again, I need to check its dependents first.

create or replace type A as object (
  x_ number, 
  y_ varchar2(10),
  member procedure to_upper
);
/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

糖果控 2024-09-04 18:38:38

根据需要查看 DBA_DEPENDENCIES、ALL_DEPENDENCIES 或 USER_DEPENDENCIES

SELECT OWNER, NAME, TYPE
  FROM DBA_DEPENDENCIES 
 WHERE REFERENCED_OWNER = [type owner]
   AND REFERENCED_NAME  = [type name]
   AND REFERENCED_TYPE  = 'TYPE'
/

Look in DBA_DEPENDENCIES, ALL_DEPENDENCIES, or USER_DEPENDENCIES as appropriate:

SELECT OWNER, NAME, TYPE
  FROM DBA_DEPENDENCIES 
 WHERE REFERENCED_OWNER = [type owner]
   AND REFERENCED_NAME  = [type name]
   AND REFERENCED_TYPE  = 'TYPE'
/
§对你不离不弃 2024-09-04 18:38:38

不要将 DROP 与 FORCE 一起使用,因为它会自动修改表(删除列),天知道还有什么可以验证所有内容。
使用类似的内容:

ALTER TYPE type_name DROP ATTRIBUTE attr_name INVALIDATE;
ALTER TYPE type_name ADD ATTRIBUTE attr_name varchar2(50) CASCADE;

这将适用于具有表/类型依赖性的类型。

Do not use DROP with FORCE, as it will automatically modify tables (delete columns) and god know what else to validate everything.
Use something like:

ALTER TYPE type_name DROP ATTRIBUTE attr_name INVALIDATE;
ALTER TYPE type_name ADD ATTRIBUTE attr_name varchar2(50) CASCADE;

This will work on types with table/type dependencies.

寄离 2024-09-04 18:38:38

如果您在表中使用过该类型,您应该能够通过如下查询查看它:

select * from all_tab_columns
where data_type_owner not in ('SYS');

但我会首先查看 Alex 使用 ALTER TYPE 的建议

If you've used the type in a table you should be able to see it through a query like :

select * from all_tab_columns
where data_type_owner not in ('SYS');

But I'd start off looking at Alex's suggestion of using ALTER TYPE

只有影子陪我不离不弃 2024-09-04 18:38:38

我确信它可以在数据字典中的某个地方找到,但不确定在哪里;并且您可能有很多不容易解决的依赖关系。但您也许可以修改现有类型: http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_4002.htm

还有一个 FORCE 选项,但仍然可能使依赖对象无效。

I'm sure it's available in the data dictionary somewhere, but not sure where off-hand; and you're likely to have lots of dependencies that aren't easy to resolve. But you may be able to modify the existing type instead: http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_4002.htm

There's also a FORCE option but that could still invalidate dependent objects.

一个人的夜不怕黑 2024-09-04 18:38:38

这是由 Oracle 中的基本限制引起的,也是不在数据库中使用 oracle 类型的另一个原因。

对于“TYPE”依赖项,您可以:

  1. DROP TYPE mytype FORCE;
  2. 然后重新创建类型 mytype 和类型 body
  3. 然后 DROP TYPE mytype_dependent FORCE;
  4. 然后重新创建 mytype_dependent 类型和类型主体。
  5. 对所有依赖类型和引用类型重复此操作。

注意:第 3..5 项是必需的,因为依赖类型无法自动重新编译或“就地”手动编译。

对于“TABLE”依赖项,您必须:

使用此处文章中的指南,其中讨论了三个相关场景。

ORA-02303:无法删除或替换具有类型或表依赖项的类型

来自 Oracle's Improbable Errors 博客

This is caused by basic restrictions in Oracle, another reason not to use oracle types in the database.

For 'TYPE' dependencies you can:

  1. DROP TYPE mytype FORCE;
  2. Then re-create the type mytype and type body
  3. Then DROP TYPE mytype_dependent FORCE;
  4. Then re-create the mytype_dependent type and type body.
  5. Repeat for all dependent and referenced types.

Note: The items 3..5 are required because dependent types cannot be automatically recompiled or manually compiled 'in place'.

For 'TABLE' dependencies you must:

Use the guidance in the article here, where it talks about the three relevant scenarios.

ORA-02303: cannot drop or replace a type with type or table dependents

from the Annals of Oracle's Improbable Errors blog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文