2014-11-02 15 views
0

它可以在一個對象表中使用兩個或三個參考?我正在創建一個比賽時間表,我需要在該表中有2個隊伍,這個隊伍是1隊和2隊,應該指向隊表。我是面向對象的Oracle的新手,我不知道我在做什麼。它可以在一個對象表中使用兩個或三個參考?

+0

我認爲這個詞是'關係',是的,這是可能的。只需創建兩個字段和兩個參考約束。 – 2014-11-02 13:58:08

回答

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%的人會用Gordon的答案來實現一個關係模型。

1

我認爲你可以做你想要的只是使用關係數據庫設計。您的表格可能如下所示:

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

這是必須使用Oracle功能完成的。這是我的任務的一部分。比賽時間表有3個屬性球隊1,球隊2和球隊贏了,這3個屬性需要參考球隊表或者是否有其他的替代方式? – Rose 2014-11-02 17:07:22

+0

還有其他的方法。這是我的方式。 – 2014-11-02 17:19:17

相關問題