我可以更改从类型派生的 table 的属性名称吗?

Can I change an attribute name from a table derived from a type?

遵循对象关系数据库模型,我想创建从类型 t_employee 派生的 tables or_doctoror_recepcionist。 这里,遵循类型结构:

DROP TYPE t_employee FORCE;
CREATE OR REPLACE TYPE t_employee AS OBJECT (
    num_employee INTEGER,
    name_employee VARCHAR2(50),
    birthdate_employee DATE
);

在这里,tables 的结构:

DROP TABLE or_doctor CASCADE CONSTRAINTS;
CREATE TABLE or_doctor OF t_employee (
    PRIMARY KEY (num_employee),
    name_employee NOT NULL,
    birthdate_employee NOT NULL
) OBJECT IDENTIFIER IS SYSTEM GENERATED;

DROP TABLE or_recepcionist CASCADE CONSTRAINTS;
CREATE TABLE or_recepcionist OF t_employee (
    PRIMARY KEY (num_employee),
    name_employee NOT NULL,
    birthdate_employee NOT NULL
) OBJECT IDENTIFIER IS SYSTEM GENERATED;

这样做,两个 table 上的属性名称都将以“employee”结尾。我可以更改属性名称,以便在我创建 table 时它们在每个 table 中都是特定的吗? 例如:

Tableor_doctor: num_doct, name_doct, birthdate_doct。 Table or_recepcionist: num_recep, name_recep, birthdate_recep.

作为一个框架挑战,不要为您的标识符添加后缀,这样您就不必担心后缀不正确:

CREATE TYPE t_employee AS OBJECT (
    num       INTEGER,
    name      VARCHAR2(50),
    birthdate DATE
);

CREATE TABLE or_doctor OF t_employee (
    PRIMARY KEY (num),
    name      NOT NULL,
    birthdate NOT NULL
) OBJECT IDENTIFIER IS SYSTEM GENERATED;

CREATE TABLE or_receptionist OF t_employee (
    PRIMARY KEY (num),
    name      NOT NULL,
    birthdate NOT NULL
) OBJECT IDENTIFIER IS SYSTEM GENERATED;

如果您尝试重命名列:

ALTER TABLE or_doctor RENAME COLUMN name TO name_doctor;

然后你会得到错误:

ORA-23291: Only base table columns may be renamed

如果您使用的是 object-derived 表,那么您似乎受困于对象的标识符;因此,使对象名称通用,以便它们适用于将要使用的每个地方。