具有嵌套表

时间:2016-09-28 08:17:30

标签: sql oracle database-design object-relational-model

我有一个超类型Person和两个(或更多)子类型Group1和Group2。

Person可以是Group1和Group2,即子类型可以重叠。

超类型包含一个嵌套表'成员资格'。

当我创建子类型表时,似乎我必须再次重复NESTED TABLE语句,否则我将收到错误消息:

SQL错误:ORA-22913:必须为嵌套表列或属性

指定表名

我有两个问题:

  • 我是否嵌套了相同的表格'成员资格'在两个子类型表下group1_table和group2_table是否正确?
  • 当我填充子类型表中的数据时,是否可以引用'到超类型表而不重复子类表中的公共值?

Supertype subtype ERD[er

CREATE TYPE membership_type AS OBJECT
(membership_number INT,
 membership_name VARCHAR2(20),
 membership_date DATE)

CREATE TYPE membership_table AS TABLE OF membership_type

CREATE TYPE person_type AS OBJECT
(name VARCHAR2(100),
 membership membership_table) NOT FINAL

CREATE TABLE person_table OF person_type
OBJECT ID SYSTEM GENERATED
NESTED TABLE membership
STORE AS person_membership

CREATE TYPE group1_type under person_type
(extraAttribute1 VARCHAR2(10))

CREATE TABLE group1_table OF group1_type
NESTED TABLE membership
STORE AS group1_membership --Is the way that I nested the membership table correct?

CREATE TYPE group2_type UNDER person_type
(extraAttribute2 VARCHAR2(50))


CREATE TABLE group2_table OF group2_type 
NESTED TABLE membership
STORE AS group2_membership --Is the way that I nested the membership table correct?

INSERT INTO person_table VALUES
('person name',
membership_table(membership_type('123', 'membership name', '01-Aug-2016')));

INSERT INTO group1_table VALUES...
--can I refer to the supertype instead of duplicating the common value here?

0 个答案:

没有答案