我目前正在尝试创建一个允许某人成为客户或员工的人员表。目前这是我的代码: -
Create Or Replace Type Person As OBJECT
(
person_id number(5) not null,
firstname varchar2(15) not null,
surname varchar2(15) not null,
address1 varchar2(70) not null,
address2 varchar2(70),
address3 varchar2(70),
postcode varchar2(9) not null
);
/
Create Or Replace Type Client Under Person
(
marital_status varchar2(10),
no_of_children number(2)
);
/
Create Or Replace Type Staff Under Person
(
job_title varchar2(15) not null,
salary number(4,2) not null,
manager_id number(5) not null
);
/
Create Table Person Of Person
(
person_id Primary Key
);
对象类型全部编译但是当它创建表时我得到以下错误: -
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
导致此错误发生的原因以及可以采取哪些措施来纠正错误。非常感谢任何帮助。
******** EDIT **********
我已将表的名称更改为person_tbl,但仍会出现相同的错误。出于某种原因,此错误现在出现在编译器日志中: -
Error: PL/SQL: Compilation unit analysis terminated
Error(1,18): PLS-00905: object [ConnectionName].PERSON is invalid
我不知道为什么它不允许我使用Person类型,因为我在成功之前已经使用了这个方法。
答案 0 :(得分:1)
不知道,为什么会收到这些错误。你应该得到错误
00955. 00000 - "name is already used by an existing object"
尝试创建与类型同名的表时。
尝试
Create Table Persons Of Person
(
person_id Primary Key
);
答案 1 :(得分:1)
你有一些问题。正如@tonirush所提到的,在数据库中不能有多个具有相同名称的对象。
此外,person
类型正在编译错误(特别是PLS-00218: a variable declared NOT NULL must have an initialization assignment
)。在解决这些错误之前,您无法基于该对象构建对象表。
您的子类型也有编译错误:PLS-00590: attempting to create a subtype UNDER a FINAL type
,但这与无法创建对象表无关。
作为脚注,本答案中的“对象”一词(以及一般的Oracle数据库中)都是重载的。在第一段中,我说的是“数据库对象”,它几乎是使用create
命令在数据库中创建的任何东西。对于其他人,我说的是“对象类型”,它们是由create type ... object
专门创建的对象。