How can I define a type in oracle11g that referenc

2019-02-23 19:16发布

I want to do something like this

create type Item as object (
    id number,
    subitems table of ref Item
)

but oracle throws an exception when I try to do it. Is this possible, and if yes then how?

2条回答
再贱就再见
2楼-- · 2019-02-23 20:06

That would be nice wouldn't it! You could try this:

create type item_ids_t is table of number;

create type Item as object (
   id number,
   subitems item_ids_t);

Which means that subitems is just a list of ids, which would then be used to look up a table indexed by id.

查看更多
欢心
3楼-- · 2019-02-23 20:15

Oracle will not compile your definition because the type Item hasn't been compiled yet. Why dont you give this a try:

Compile this:

CREATE OR REPLACE TYPE Item;

CREATE OR REPLACE TYPE items_table IS TABLE OF REF item;

and then try:

CREATE OR REPLACE TYPE item AS OBJECT (
   id number,
   subitems items_table
)
查看更多
登录 后发表回答