可以在一个对象表中使用两个或三个ref吗?

时间:2014-11-02 13:36:06

标签: sql oracle

可以在一个对象表中使用两个或三个ref吗?我正在为比赛时间表创建一个表,我需要在该表中有2个团队,即团队1和团队2,它们应该指向Team表。我是面向对象的oracle的新手,我不知道我在做什么。

2 个答案:

答案 0 :(得分:1)

我认为你可以使用关系数据库设计做你想做的事。您的表格可能类似于:

create table matches (
    matchid int primary key,
    team1_id int references teams(id),
    team2_id int references teams(id),
    . . .
);

答案 1 :(得分:0)

对象表可以包含多个references,如下所示。

--Create types and tables.
create or replace type team_type is object
(
    id number,
    name varchar2(100)
);

create table team of team_type;

create or replace type match_type is object
(
    id number,
    match1 ref team_type,
    match2 ref team_type
);

create table match of match_type;

--Sample inserts.
insert into team values(1, 'A');
insert into team values(2, 'A');

insert into match values(
    1,
    (select ref(t) from team t where id = 1),
    (select ref(t) from team t where id = 2)
);

正如您所发现的,Oracle的对象关系功能很少在课堂外使用。询问关于它们的最简单的问题通常会引起混淆。世界上99.9%的人会使用戈登的答案来实现关系模型。