简体   繁体   English

Oracle 数据库 PL/SQL 是否支持递归对象? 一个 object 在严格的分层树中包含相同类型的数组/表

[英]Does Oracle Database PL/SQL support recursive objects? an object the includes array/table of same type in a strict hierarchical tree

In the Object-Relational Developer's Guide I found reference to subordinate/embedded types that are different - department includes address, for instance.在 Object-Relational Developer's Guide 中,我发现引用了不同的从属/嵌入类型 - 例如,部门包括地址。 This document also includes a section of resolving circular references, but again, between objects of different types.该文档还包括解决循环引用的部分,但同样是在不同类型的对象之间。 I am looking for the object to reference itself.我正在寻找 object 来引用自己。

create or replace type a_obj is object (myself varchar2(10), parent      number, children number);
/
create or replace type c_obj is table of ref a_obj;
/
create or replace type a_obj is object (myself varchar2(10), parent a_obj, children c_obj);
/
Type A_OBJ compiled


Type C_OBJ compiled


Error starting at line : 12 in command -
create or replace type a_obj is object (myself varchar2(10), parent a_obj, children c_obj);
Error report -
ORA-02303: cannot drop or replace a type with type or table dependents
02303. 00000 -  "cannot drop or replace a type with type or table dependents"
*Cause:    An attempt was made to drop or replace a type that has
           type or table dependents.
*Action:   For DROP TYPE, drop all type(s) and table(s) depending on the
           type and then retry the operation, or use the FORCE option.
           For CREATE TYPE, drop all type(s) and table(s) depending on the
           type and then retry the operation, or drop all table(s) depending
           on the type and retry with the FORCE option.

Forward declare the type and set the parent to be a REF type:前向声明类型并将父级设置为REF类型:

create type a_obj;
/

create type c_obj is table of ref a_obj;
/

create or replace type a_obj is object (
  myself   varchar2(10),
  parent   REF a_obj,
  children c_obj
);
/

db<>fiddle here db<> 在这里摆弄

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM