std::vector
当我尝试运行上面的查询时,它会生成以下错误。
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits(hostChg,vDate,refDoc,docChg))
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)
)
);/
我认为逗号不应该存在问题。怎么解决这个问题?
答案 0 :(得分:0)
在嵌套表类型的左括号处引发错误:
INSERT INTO PatientTbl(sysID,id,name,dob,phone,hospVisits(hostChg, ...
^
您的PatientTbl
有一个嵌套的表格列。您似乎试图在insert语句中指定该表的对象类型的详细信息,这是不正确的。
假设嵌套表列名为hospVisits
,您只需执行:
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)
)
);
但你的嵌套表结构也是错误的;您尝试使用两个单独的hospVisitsNt_ty_tbl
,每个hospVisits_ty
,而不是一个hospVisitsNt_ty_tbl
多个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)
)
);
我也转而使用ANSI日期文字,假设(并希望)这些列实际上是日期而不是字符串。您依赖于NLS参数,而这些参数通常无法控制,隐式日期转换不是一个好主意,因为当其他人运行您的代码时,它可能会失败。
即使在您自己的环境中,您也会得到意想不到的结果,因为您使用的是2位数年份;字符串'3-FEB-49'
将被隐式转换为2049,而不是1949(看起来像你期望的那样):
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
如果您的defaut模型具有RR,RRRR或YY,那就是这样;如果碰巧有YYYY那么你就得到了0049-02-03。
使用一些已编辑的数据类型测试对象构建和插入,因为您还没有提供:
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.