Oracle SQL - Table 创建问题

Oracle SQL - Table Create Issue

我目前正在尝试创建一个人 table 允许一个人成为客户或员工。目前这是我的代码:-

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
);

对象类型全部编译但是当它去创建 table 我得到以下错误:-

SQL Error: ORA-00902: invalid datatype
00902. 00000 -  "invalid datatype"

导致此错误发生的原因以及可以采取哪些措施来纠正它。非常感谢任何帮助。

********编辑**********

我已将 table 的名称更改为 person_tbl,但仍然出现相同的错误。由于某种原因,此错误现在出现在编译器日志中:-

Error: PL/SQL: Compilation unit analysis terminated
Error(1,18): PLS-00905: object [ConnectionName].PERSON is invalid

我不知道为什么它不让我使用 Person 类型,因为我已经成功地尝试过这个方法。

不知道,为什么会出现这些错误。你应该得到错误

00955. 00000 -  "name is already used by an existing object"

尝试创建与类型同名的 table 时。

尝试

Create Table Persons Of Person
(
  person_id Primary Key
);

你有一些问题。正如@tonirush 提到的,同名的数据库中不能有多个对象。

此外,person 类型编译时出现错误(特别是 PLS-00218: a variable declared NOT NULL must have an initialization assignment)。在解决这些错误之前,您无法基于对象构建对象 table。

您的子类型也有编译错误:PLS-00590: attempting to create a subtype UNDER a FINAL type,但这与无法创建对象无关table。


作为脚注,此答案(通常在 Oracle 数据库中)中的 "object" 一词被重载。在第一段中,我说的是 "database objects",这几乎是使用 create 命令在数据库中创建的任何内容。对于其余部分,我说的是 "object types",它们是由 create type ... object 特别创建的对象。