The error is being raised at the opening parenthesis of the nest table type:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits(hostChg, ...
^
Your PatientTbl
has a nested table column. You seem to be trying to specify the details of that table's object type inside the insert statement, which isn't correct.
Assuming that nest table column is called hospVisits
you would just do:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits)
VALUES('P002','491221019V','Dulani Perera','3-FEB-49',
phone_arr_ty(0112233211),hospVisitsNt_ty_tbl(hospVisits_ty(75.00,'25-MAY-06',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00)),
hospVisitsNt_ty_tbl(hospVisits_ty(90.00,'29-MAY-06',(SELECT REF(d) FROM DoctorTbl d
WHERE d.regNo=2344114344),300.00)
)
);
But your nested table construction is wrong too; you are trying to use two separate hospVisitsNt_ty_tbl
with a single hospVisits_ty
in each, rather than a single hospVisitsNt_ty_tbl
with multiple hospVisits_ty
:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits)
VALUES('P002','491221019V','Dulani Perera',date '1949-02-03',
phone_arr_ty(0112233211),
hospVisitsNt_ty_tbl(
hospVisits_ty(75.00, date '2006-05-25',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00),
hospVisits_ty(90.00,date '2006-05-29',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2344114344),300.00)
)
);
I've also switched to using ANSI date literals, on the assumption (and hope) that those columns are actually dates not strings. You were relying on NLS parameters, which you don't usually have control over, and implicit date conversion is not a good idea as it can fail when other people run your code.
You will get unexpected results even in your own environment because you're using 2-digit years; the string '3-FEB-49'
would be implicit converted to 2049, not 1949 (which is looks like you would expect):
alter session set nls_date_format = 'DD-MON-RR';
select to_char(to_date('3-FEB-49'), 'YYYY-MM-DD') from dual;
TO_CHAR(TO
----------
2049-02-03
And that's if your defaut model has RR, RRRR or YY; if it happens to have YYYY then you'd get 0049-02-03.
Object build and insertion tested with some made-up data types, as you haven't provided yours:
create type doctor_ty as object (regNo number)
/
create table DoctorTbl of doctor_ty
/
create type hospVisits_ty as object (hostChg number,vDate date,
refDoc ref doctor_ty,docChg number)
/
show errors
create type hospVisitsNt_ty_tbl as table of hospVisits_ty
/
create type phone_arr_ty as object (num number)
/
create table PatientTbl(sysID varchar2(4),id varchar2(12),name varchar2(30),dob date,
phone phone_arr_ty,hospVisits hospVisitsNt_ty_tbl)
nested table hospVisits store as hospVisitsNt return as locator;
/
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits)
VALUES('P002','491221019V','Dulani Perera',date '1949-02-03',
phone_arr_ty(0112233211),
hospVisitsNt_ty_tbl(
hospVisits_ty(75.00, date '2006-05-25',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2342111322),550.00),
hospVisits_ty(90.00,date '2006-05-29',
(SELECT REF(d) FROM DoctorTbl d WHERE d.regNo=2344114344),300.00)
)
);
1 row inserted.