2016-10-18 73 views
-1

我有兩個表如何用多個表創建視圖?

CREATE TABLE table1(id NUMBER, name VARCHAR2(10)); 
CREATE TABLE table2(id NUMBER, dept VARCHAR2(4)); 

現在,我想創建一個包含ID和名稱從表表2表table1和部門的視圖。我有一個查詢,如

CREATE VIEW table_view 
AS SELECT t1.id,t1.name,t2.dept 
FROM table1 t1 full outer join table2 t1 
ON t1.id = t2.id; 

但我得到的錯誤:ORA-00904:「T2」。「ID」:無效的標識符。 幫我清除錯誤。謝謝。

+0

你必須在表2 T1錯誤的別名 – Thomas

回答

1

你給了兩個表相同的別名outer join table2 t1應該outer join table2 t2

CREATE VIEW table_view 
AS SELECT t1.id,t1.name,t2.dept 
FROM table1 t1 
    full outer join table2 t2 --<< here 
       ON t1.id = t2.id; 
+0

哎呀..!非常感謝 :) –