私は、オブジェクト型が同じ型のコレクションのメンバーコレクションの前にオブジェクト型とオブジェクト型の前にコレクションを定義することができます。あなたがサブタイプにスーパータイプから絞り込むことtreat
を使用PERSON_Tの実装に
-- supertype
create type object_t is object;
create type object_list_t is table of ref object_t;
-- subtype
create type person_t under object_t (
name varchar2(20)
,children object_list_t
);
そして:循環依存関係の1を解除するには、次のファッション(警告非テスト擬似コードは以下の)に間接のレベルを導入する必要があります。
もう1つのアイデアは、オブジェクトの関係を特定の関係テーブルに持たせることです。以下の例を参照してください。
まず、単純な人型を作成します。
create type person_t is object (
name varchar2(20)
);
/
show errors
create table persons of person_t;
insert into persons values(person_t('Grandfather'));
insert into persons values(person_t('Father'));
insert into persons values(person_t('Mother'));
insert into persons values(person_t('Son 1'));
insert into persons values(person_t('Daughter 1'));
insert into persons values(person_t('Son 2'));
第二の親子関係のテーブルを作成します。
create table x (
parent ref person_t
,child ref person_t
);
-- build a family tree
insert into x values(
(select ref(p) from persons p where name = 'Grandfather')
,(select ref(p) from persons p where name = 'Father')
);
insert into x values(
(select ref(p) from persons p where name = 'Father')
,(select ref(p) from persons p where name = 'Son 1')
);
insert into x values(
(select ref(p) from persons p where name = 'Father')
,(select ref(p) from persons p where name = 'Son 2')
);
insert into x values(
(select ref(p) from persons p where name = 'Father')
,(select ref(p) from persons p where name = 'Daughter 1')
);
insert into x values(
(select ref(p) from persons p where name = 'Mother')
,(select ref(p) from persons p where name = 'Son 1')
);
insert into x values(
(select ref(p) from persons p where name = 'Mother')
,(select ref(p) from persons p where name = 'Son 2')
);
insert into x values(
(select ref(p) from persons p where name = 'Mother')
,(select ref(p) from persons p where name = 'Daughter 1')
);
今、あなたは古き良きSQLで家系図をたどることができます。
column parent format a30
column child format a30
select deref(child) as child from x where deref(parent).name = 'Father';
CHILD(NAME)
------------------------------
PERSON_T('Son 1')
PERSON_T('Son 2')
PERSON_T('Daughter 1')
select deref(parent) as parent, deref(child) as child
from x
start with deref(parent).name = 'Grandfather'
connect by prior child = parent
;
PARENT(NAME) CHILD(NAME)
------------------------------ ------------------------------
PERSON_T('Grandfather') PERSON_T('Father')
PERSON_T('Father') PERSON_T('Son 1')
PERSON_T('Father') PERSON_T('Son 2')
PERSON_T('Father') PERSON_T('Daughter 1')
ref
とderef
機能はDatabase Object-Relational Developer's Guideで説明されています。これは、Oracleオブジェクト型を操作する場合に慣れておくべきドキュメントです。
これは存在しない型を参照しようとしていて、存在しない型を参照している型を作成しようとしているときに構文上正しくありません。あなたは最初に完全な定義をする必要があります。 – XING