数据类型不一致:尝试插入数据时,预期的REF出现了..错误 [英] Inconsistent datatypes: expected REF got .. error when trying to insert data

查看:132
本文介绍了数据类型不一致:尝试插入数据时,预期的REF出现了..错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长话短说,我想要做的就是将一些数据插入表中,而在理解错误之处时遇到了一些问题.我让代码自言自语.希望你能帮帮我.预先感谢!

Long story short what I'm trying to do is to insert some data into a table and I'm having some problems understanding what is wrong. I'll let the code talk for itself. Hope you can help me out. Thanks in advance!

CREATE OR REPLACE TYPE Departament IS OBJECT (
  deptno NUMBER(2),
  dname CHAR(14)
  );
/

CREATE OR REPLACE TYPE Employee IS OBJECT (
  empno NUMBER(4),
  ename CHAR(10),
  dept REF Departament,
  sal NUMBER(7,2)
  ) NOT FINAL;
/

CREATE OR REPLACE TYPE Manager UNDER Employee (
  nrEmp NUMBER(2)
  );
/

CREATE TABLE departament_list AS (SELECT deptno, dname FROM dept);
/

CREATE TABLE manager_list OF Manager;
/

INSERT INTO manager_list VALUES(Manager(7782, 'JOHN', Departament(20, 'TEXAS'), 6000, 2));

这是最后一行的问题,我得到以下错误

Well here is the problem on the last line I get the following error

ORA-00932:数据类型不一致:获得了预期的REF SYS.DEPARTAMENT SYS.DEPARTAMENT.

ORA-00932: inconsistent datatypes: expected REF SYS.DEPARTAMENT got SYS.DEPARTAMENT.

现在不要误会我已经尝试使用以下方法进行整个选择:从departament_list d的REF(d)...但是我收到另一个错误,指出默认构造函数的参数数量不正确.

Now don't get me wrong I have tried doing the whole select thingy with: REF(d) from departament_list d ... but I get another error saying incorrect number of arguments for default constructor.

也许我做错了这个方法,您可以帮助您弄清楚我弄错了什么.再次感谢!

Maybe I'm doing this the wrong way and you can help shed some light on where I'm mistaken. Thanks again!

推荐答案

这似乎是错误原因:

CREATE TABLE departament_list AS (SELECT deptno, dname FROM dept);

对我有用的步骤:

CREATE TABLE departament_list of Departament;

insert into departament_list values (20, 'Texas');

CREATE TABLE manager_list OF Manager;

INSERT INTO manager_list VALUES(Manager(7782, 'JOHN', 
  (select ref(d) from departament_list d where deptno=20), 6000, 2));

来自文档:

OF子句可让您显式创建类型的对象表 object_type.对象表的列对应于 类型为object_type的顶级属性.每行将包含一个 对象实例,并且每个实例都会被分配一个唯一的值, 插入行时系统生成的对象标识符.

The OF clause lets you explicitly create an object table of type object_type. The columns of an object table correspond to the top-level attributes of type object_type. Each row will contain an object instance, and each instance will be assigned a unique, system-generated object identifier when a row is inserted.

这篇关于数据类型不一致:尝试插入数据时,预期的REF出现了..错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆