我可以创建一个包含嵌套表作为属性的对象表吗?

时间:2011-04-25 05:31:05

标签: oracle plsql user-defined-types

以下是我的OR架构的片段:

CREATE TYPE artist_table_type AS TABLE OF REF artist_type;
/

CREATE TYPE track_type AS OBJECT (
    title VARCHAR(1000),
    duration INT,
    release_date DATE,

    producers artist_table_type,

    MEMBER FUNCTION getProducers RETURN artist_table_type,
    MEMBER FUNCTION getRemixers RETURN artist_table_type
);
/
CREATE TABLE track_obj_table OF track_type;

当我尝试运行时,我收到错误:

CREATE TABLE track_obj_table OF track_type
*
ERROR at line 1:
ORA-22913: must specify table name for nested table column or attribute

我怀疑这是因为track_type对象中的表类型?

1 个答案:

答案 0 :(得分:6)

这只是意味着您必须为嵌套表提供存储子句:

SQL> CREATE TABLE track_obj_table OF track_type;
CREATE TABLE track_obj_table OF track_type
*
ERROR at line 1:
ORA-22913: must specify table name for nested table column or attribute


SQL> CREATE TABLE track_obj_table OF track_type
  2  NESTED TABLE producers STORE AS producers_nt
  3  /

Table created.

SQL> desc track_obj_table
 Name                                      Null?    Type
 ----------------------------------------- -------- -------------------------
 TITLE                                              VARCHAR2(1000)
 DURATION                                           NUMBER(38)
 RELEASE_DATE                                       DATE
 PRODUCERS                                          ARTIST_TABLE_TYPE

SQL>