当我尝试将数据插入下表时。
create table Policies of policy_t(
pid primary key,
inscar references Cars
)nested table claims store as claims_ntable;
使用以下查询,
insert into policies
select policy_t ('PLC1234','12 Mar 2017','12 Mar 2018',REF(C),175000,claim_t('CLAIM1234567','12 Feb 2017','56000',REF(T)))
from cars C,customer T
where C.regno = 'CAB3233' and T.cid = '123ABC'
我得到以下错误
Error starting at line : 1 in command -
insert into policies
select policy_t ('PLC1234','12 Mar 2017','12 Mar 2018',REF(C),175000,claim_t('CLAIM1234567','12 Feb 2017','56000',REF(T)))
from cars C,customer T
where C.regno = 'CAB3233' and T.cid = '123ABC'
Error at Command Line : 3 Column : 25
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
如何在此表中插入数据?
其他相关的对象类型和表,
客户对象类型
create type Customer_t as object(
cid char(6),
cusname varchar(15),
birthdate date,
phone char(10),
address varchar(50)
);
客户表
create table Customers of customer_t(
cid primary key
);
声明对象类型
create type claim_t as object(
claimno char(12),
cdate date,
amount number(8,2),
claimant ref customer_t
);
声明嵌套表
create type Claim_ntab is table of claim_t;
汽车对象类型
create type Car_t as object(
regno char(9),
make varchar(12),
model varchar(10),
mdate date,
owner ref customer_t,
value number(8,2)
);
汽车桌子
create table Cars of car_t(
regno primary key,
owner references Customers
);
策略对象类型
create type policy_t as object(
pid char(7),
sdate date,
edate date,
inscar ref car_t,
premium number(6,2),
claims claim_ntab
)
政策表
create table Policies of policy_t(
pid primary key,
inscar references Cars
)nested table claims store as claims_ntable;
答案 0 :(得分:1)
更正表名(customer
/ customers
)后,下一个问题是customers.claims
是claim_ntab
,但是您试图插入{{1} } 进去。试试这个:
claim_t
编辑:我使用对象引用将您的insert into policies
select policy_t
( 'PLC1234'
, date '2017-03-12'
, date '2018-03-12'
, ref(ca)
, 175000
, claim_ntab(claim_t
( 'CLAIM1234567'
, date '2017-02-12'
, '56000'
, ref(cu) ) )
)
from cars ca
join customers cu
on ref(cu) = ca.owner
where ca.regno = 'CAB3233'
and cu.cid = '123ABC'
子句联接更改为ANSI样式。老实说,我以前没有使用过这种语法,而且我怀疑很少有人使用过,因此需要进行一些测试。
答案 1 :(得分:0)
您将表格命名为Customers
,请注意复数形式。
所以改变
from cars C,customer T
到
from cars C,customers T
甚至更好,无论如何,请使用显式JOIN
语法重写它。
答案 2 :(得分:0)
INSERT INTO _table1_ (_field1_, _field2_, _field3_)
字段名称,而不是值
SELECT _field1_, _field2_, _field3_ FROM _table2_ WHERE ... ;
INSERT INTO _table1_ (_field1_, _field2_, _field3_)
VALUES ('some text', 'some text', 'some text');
,如果您想添加一些值