创建涉及继承的嵌套表时出错

时间:2014-11-26 01:25:18

标签: oracle orm plsql user-defined-types

我的结构有点复杂如下:

create or replace type user_typ as object(
  user_id number(19,0),
  username nvarchar2(40 char)
);

我从这里继承了applicant_typ:

create or replace type applicant_typ under user_typ (
  resume_text nclob
);

我的设计涉及申请人可以申请的工作。为此,我按如下方式创建了一个application_typ:

create or replace TYPE Application_typ AS OBJECT (
  application_id NUMBER,
  candidate applicant_typ,
  time_of_app DATE
);

CREATE TYPE Application_tab IS TABLE OF Application_typ; 

现在我想创建一个名为Job_typ的对象类型,以及一个包含这些对象的表,其中将有一个用于应用程序的嵌套表:

CREATE OR REPLACE TYPE Job_typ AS OBJECT (
  job_ID NUMBER,
  company_ID NUMBER,
  description NVARCHAR2(1000),
  name NVARCHAR2(200),
  application Application_tab,
  MAP MEMBER FUNCTION job_no RETURN NUMBER,
  MEMBER PROCEDURE no_of_applicants 
);

所有这一切都很好。问题是当我尝试创建Job_typ类型的表时:

CREATE TABLE Job_tab OF Job_typ 
NESTED TABLE application STORE AS application_nt;

这不起作用,给出错误:

SQL Error: ORA-02320: failure in creating storage table for nested table column APPLICATION
ORA-22913: must specify table name for nested table column or attribute
02320. 00000 -  "failure in creating storage table for nested table column %s"
*Cause:    An error occurred while creating the storage table for the
       specified nested table column.

我做错了什么?

编辑:我尝试了一些不同的东西。如果我按如下方式更改application_typ:

CREATE OR REPLACE TYPE Application_typ AS OBJECT (
  application_id NUMBER,
  candidate User_Typ, -- NOTE: This attribute is now of type User_typ instead of the inherited type
  time_of_app DATE,
);

 CREATE TYPE Application_tab IS TABLE OF Application_typ; 

然后其他一切正常,我可以创建Job表。为什么我在使用继承类型时遇到错误?

1 个答案:

答案 0 :(得分:0)

我在Oracle 11.2.0.1中尝试了以下操作,但没有收到任何错误。我做了一个小小的改变:

CREATE OR REPLACE TYPE user_typ AS OBJECT
(
    user_id NUMBER (19, 0),
    username NVARCHAR2 (40 CHAR)
) NOT FINAL;                            -- << Notice the NOT FINAL keyword

create or replace type applicant_typ under user_typ (
  resume_text nclob
);

CREATE OR REPLACE TYPE Application_typ AS OBJECT
(
    application_id NUMBER,
    candidate applicant_typ,
    time_of_app DATE
);

CREATE TYPE Application_tab IS TABLE OF Application_typ;

CREATE OR REPLACE TYPE Job_typ AS OBJECT
(
    job_ID NUMBER,
    company_ID NUMBER,
    description NVARCHAR2 (1000),
    name NVARCHAR2 (200),
    application Application_tab,
    MAP MEMBER FUNCTION job_no
        RETURN NUMBER,
    MEMBER PROCEDURE no_of_applicants
);

CREATE TABLE Job_tab OF Job_typ
NESTED TABLE application
    STORE AS application_nt;

在尝试创建所有类型和关键字时,我收到错误:

[Error] PLS-00590 (10.1): PLS-00590: attempting to create a subtype UNDER a FINAL type

这是因为Oracle不允许在FINAL类型上创建子类型。如果您没有为基本类型定义任何finalizing子句,则默认值为FINAL

详细了解Oracle Docs


如果您正在编写现实世界(阅读行业),我建议不要使用嵌套表作为列类型。你最终会花费你的整个生命来试图嵌套和取消嵌套。我建议你尽可能地规范化你的模式,并为PL / SQL代码块中的操作留下嵌套表。