如何使用 REF 引用行对象?
我有两个实体:客户和订单,我都为其创建了类型。 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
任何帮助将不胜感激。
I have two entities, Customer and Order, both of which I have created types for. The SQL type declarations are:
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
);
The idea being that a customer can place 1..* orders. An order is placed by 1..1 customer.
I've also created CustomerTable and OrderTable tables like so:
CREATE TABLE "CUSTOMERTABLE" OF "CUSTOMERTYPE";
CREATE TABLE "ORDERTABLE" OF "ORDERTYPE";
There is an entry in CustomerTable with customerId = '123456'. When I execute the following:
INSERT INTO OrderTable
SELECT OrderType (REF(c), '1234567890', '02-Nov-2009', 99)
FROM CustomerTable c
WHERE c.customerId = '123456';
Oracle reports that the row has been inserted. However, when I check the data I get error:
ORA-00932: inconsistent datatypes: expected NUMBER got REF MILKPLUSVELLOCET.CUSTOMERTYPE
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“当我检查数据时”是什么意思?
这适用于我的机器:
What do you mean by 'when I check the data'?
This works on my machine: