【问题标题】:How can I define a type in oracle11g that references a collection of that type?如何在 oracle11g 中定义引用该类型集合的类型?
【发布时间】:2010-11-06 11:52:57
【问题描述】:
我想做这样的事情
create type Item as object (
id number,
subitems table of ref Item
)
但是当我尝试这样做时,oracle 会引发异常。这可能吗?如果是,那怎么办?
【问题讨论】:
标签:
database
oracle
object-relational-model
【解决方案1】:
Oracle 不会编译您的定义,因为类型 Item 尚未编译。你为什么不试试这个:
编译:
CREATE OR REPLACE TYPE Item;
CREATE OR REPLACE TYPE items_table IS TABLE OF REF item;
然后尝试:
CREATE OR REPLACE TYPE item AS OBJECT (
id number,
subitems items_table
)
【解决方案2】:
那就太好了,不是吗!你可以试试这个:
create type item_ids_t is table of number;
create type Item as object (
id number,
subitems item_ids_t);
这意味着 subitems 只是一个 id 列表,然后将用于查找由 id 索引的表。