oracle-databaseplsqloracle11gormobject-relational-model

Error While Creating Nested Table in Oracle


Below is the Tables i have created.

CREATE TYPE ft_obj AS OBJECT (
    ftid         NUMBER(5),
    ftlocation   VARCHAR(30),
    country      VARCHAR(10)
);
/

CREATE TABLE ft_table OF ft_obj (
    ftid PRIMARY KEY
) OBJECT IDENTIFIER IS PRIMARY KEY;
/

CREATE TYPE frod_obj AS OBJECT (
    prodid           NUMBER(6),
    ft_ref           ft_obj,
    proddesc         VARCHAR(50),
    costperitem      DECIMAL,
    labcostperitem   DECIMAL
);
/

CREATE TABLE frod_table OF frod_obj (
    prodid PRIMARY KEY
) OBJECT IDENTIFIER IS PRIMARY KEY;

CREATE TYPE wf_obj AS OBJECT (
    wfid           NUMBER,
    ft_ref         ft_obj,
    wfname         VARCHAR(30),
    taxcode        INT,
    yearlyincome   DECIMAL,
    yearlytax      DECIMAL
);
/

CREATE TABLE wf_table OF wf_obj (
    wfid PRIMARY KEY
) OBJECT IDENTIFIER IS PRIMARY KEY;
/

CREATE TYPE wfusage_obj AS OBJECT (
    jobdate         DATE,
    jobhours        INT,
    jobhourlyrate   DECIMAL,
    jobposted       CHAR,
    wfid_ref        REF wf_obj
);
/

CREATE TYPE wfusage_nesttabtyp AS
    TABLE OF wfusage_obj;
/

CREATE TABLE wfusage_objtab OF wfusage_obj;
/

CREATE TYPE odetails_obj AS OBJECT (
    mfid           NUMBER,
    prodid_ref     REF frod_obj,
    quantity       INT,
    itemprice      DECIMAL,
    wfusage_ntab   wfusage_nesttabtyp
);
/

CREATE TYPE odetails_nesttabtyp AS
    TABLE OF odetails_obj;
/

CREATE TYPE prod_obj AS OBJECT (
    prodoid          NUMBER,
    odate            DATE,
    promisedate      DATE,
    completiondate   DATE,
    shipmentdate     DATE,
    status           VARCHAR(20),
    odetails_ntab    odetails_nesttabtyp
);
/

CREATE TABLE prod_objtab OF prod_obj (
    PRIMARY KEY ( prodoid )
) OBJECT IDENTIFIER IS PRIMARY KEY
NESTED TABLE odetails_ntab STORE AS oprod_ntab ( (
    PRIMARY KEY ( nested_table_id,
                  mfid )
)
ORGANIZATION INDEX
COMPRESS ) RETURN AS LOCATOR
/

ALTER TABLE oprod_ntab ADD (
    SCOPE FOR ( prodid_ref ) IS frod_table
);
/

Getting the below error while creating Nested Table.

ORA-02320: failure in creating storage table for nested table column odetails_ntab ORA-25175: no PRIMARY KEY constraint found 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. *Action: See the messages that follow for more details. If the situation they describe can be corrected, do so; otherwise contact Oracle Support.

    INSERT INTO prod_objtab  VALUES ( 45000,
    '12-April-2019',
    '01-MAy-2019',
    '01-MAy-2019',
    '01-MAy-2019',
    'COMPLETED',
    odetails_nesttabtyp()
);
INSERT INTO TABLE (SELECT pr.odetails_ntab  FROM prod_objtab pr WHERE pr.prodorderid = 45000 ) 
                    values (45001,(SELECT REF(pt) FROM frod_table pt WHERE pt.prodid = 10001 ),100,500,
                    wfusage_nesttabtyp(wfusage_obj('12-April-2019',60,100,'AME',
                    (SELECT REF(wf) FROM wf_table wf WHERE wf.wfid = 240))));

getting the error in line 9 ORA-01401: inserted value too large for column


Solution

  • ORA-02320: failure in creating storage table for nested table column odetails_ntab ORA-25175: no PRIMARY KEY constraint found 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. *Action: See the messages that follow for more details. If the situation they describe can be corrected, do so; otherwise contact Oracle Support.

    Since you have done Multi-level nesting, while creating the table you need 2 levels of Storage as well for the Nested tables. See below how you can do it.

    CREATE TABLE prod_objtab OF prod_obj (
        PRIMARY KEY ( prodoid )
    ) OBJECT IDENTIFIER IS PRIMARY KEY 
    NESTED TABLE odetails_ntab STORE AS oprod_ntab ( ( PRIMARY KEY (NESTED_TABLE_ID, mfid )) 
    ORGANIZATION INDEX COMPRESS
    NESTED TABLE wfusage_ntab STORE AS  XX ) RETURN AS LOCATOR;
    

    Read more at https://docs.oracle.com/en/database/oracle/oracle-database/18/adobj/multilevel-collection-types.html#GUID-76D5A6B0-28AD-483D-942C-B7F3B90AC379