Below is the Table/Object type Creation Query. Tables are created successfully
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
NESTED TABLE wfusage_ntab STORE AS wforder_ntab
)
RETURN AS LOCATOR
/
ALTER TABLE oprod_ntab ADD (
SCOPE FOR ( prodid_ref ) IS frod_table
);
/
While inserting Data in the nested table getting the Error ORA-01401: inserted value too large for column. Below is the insert Query
INSERT INTO prod_objtab VALUES (
46000,
'25-April-2019',
'12-May-2019',
'13-May-2019',
'13-May-2019',
'COMPLETED',
odetails_nesttabtyp(
odetails_obj(46001
,(SELECT REF(pt)
FROM frod_table pt
WHERE pt.prodid = 10002)
,100
,400
,wfusage_nesttabtyp(
wfusage_obj('25-April-2019'
,60
,100
,'AME',
(SELECT REF(wf)
FROM wf_table wf
WHERE wf.wfid = 252)
)
)
)
)
)
getting the error in line 9
ORA-01401: inserted value too large for column
Having spent over an hour debugging this I feel at liberty to say, what a horrible data model. Nested objects like this exemplify the inherent problems of OO as a method for managing data.
Anyway, the problem is this (inevitably the last thing I looked at):
'AME'is three characters long. This is populatingwfusage_obj.jobposted, which you have defined as CHAR. Legitimate syntax but if we don't specify the data length it defaults to CHAR(1). Obviously this is two characters short for'AME'. It needs to be (at least) CHAR(3).Once you've fixed this you will trip over
This is because you have defined your tables with OBJECT IDENTIFIER IS PRIMARY KEY. Consequently you can't use a REF on those tables. So, you need to remove that from the table definitions to make your code work.
I have posted a demo on db<>fiddle