【问题标题】:How to create views with multiple tables?如何创建具有多个表的视图?
【发布时间】:2016-10-18 05:59:15
【问题描述】:

我有两张桌子

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

现在,我想创建一个视图,其中包含表 table1 中的 id 和 name 以及表 table2 中的 dept。我有一个类似的查询

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": invalid identifier。 帮我清除错误。谢谢。

【问题讨论】:

  • 你在 table2 t1 有错误的别名

标签: sql oracle join view


【解决方案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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多