1

我有两个实体,客户和订单,我都为它们创建了类型。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

任何帮助将不胜感激。

4

1 回答 1

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';
于 2009-11-03T07:22:24.333 回答