sql - 插入到子类型列为 : Type Inheritance, 的表中 面向对象的 SQL

标签 sql oracle oracle11g

当我尝试将数据插入下表时。

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)
);

车 table

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;

最佳答案

更正表名(customer/customers)后,下一个问题是customers.claims 是一个claim_ntab 但您正试图将 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'

编辑:我使用对象引用将您的 where 子句连接更改为 ANSI 样式。老实说,我以前没有使用过这种语法,而且我怀疑很少有人使用过,因此需要进行一些测试。

关于sql - 插入到子类型列为 : Type Inheritance, 的表中 面向对象的 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51891202/

相关文章:

mysql - 如果表只包含外键,表可以自动填充吗?

mysql - 优化 "SQL Where Clause"的表设计

c# - 如何使用 SQL 查询更新表中的多行?

linux - 甲骨文Linux前端

oracle11g - Oracle NUMTOYMINTERVAL

mysql - 改变 MySQL 列编码,级联到 FK

sql - 我怎样才能摆脱动态SQL

java - 创建一个通用的PreparedStatement方法来检查表中是否存在值

oracle - Oracle 11g 分区表上的并发统计信息收集

oracle - 获取查询的运行时执行计划