我有两个实体,即客户和订单,我为其创建了两种类型。 SQL类型声明是:
CREATE OR REPLACE TYPE "CUSTOMERTYPE" AS OBJECT (
customerId CHAR(6),
name VARCHAR2(50),
address VARCHAR2(255),
telephone CHAR(11)
);
CREATE OR REPLACE TYPE "ORDERTYPE" AS OBJECT (
customer REF CustomerType,
orderId CHAR(10),
orderDate DATE,
totalCost FLOAT
);
客户可以下1 ... *订单。订单由1..1客户下达。
我还创建了CustomerTable和OrderTable表,如下所示:
CREATE TABLE "CUSTOMERTABLE" OF "CUSTOMERTYPE";
CREATE TABLE "ORDERTABLE" OF "ORDERTYPE";
CustomerTable中有一个条目,customerId ='123456'。当我执行以下操作时:
INSERT INTO OrderTable
SELECT OrderType (REF(c), '1234567890', '02-Nov-2009', 99)
FROM CustomerTable c
WHERE c.customerId = '123456';
Oracle报告已插入该行。但是,当我检查数据时,我收到错误:
ORA-00932:数据类型不一致:预期NUMBER获得REF MILKPLUSVELLOCET.CUSTOMERTYPE
非常感谢任何帮助。
答案 0 :(得分:0)
“检查数据时”是什么意思?
这适用于我的机器:
declare
cust customertype;
begin
cust := new customertype('111111', 'Mr. Burns', '42 Mil,ky Way', '+41 75 000');
insert into customertable values cust;
end;
/
INSERT INTO OrderTable
SELECT OrderType (REF(c), '1234567890', '02-Nov-2009', 99)
FROM CustomerTable c
WHERE c.customerId = '111111';
--
select * from ordertable;
select o.customer.name from ordertable o where o.orderid = '1234567890';