尝试从2个表创建视图但不包含任何数据

时间:2014-01-06 13:40:40

标签: sql oracle

使用以下语句创建视图。这一切似乎都有效,但那里没有数据 - 我需要指定字符串吗?不知道我在这做什么?

CREATE OR REPLACE FORCE VIEW NEW_VIEW_VW
(
   URL,
   ORGANISATION,
   CATEGORY,
   SEARCH_1,
   SEARCH_2
)
AS
   SELECT DISTINCT,
   TABLE1.SERV_URL,
   TABLE2.ORGANISATION,
   TABLE1.SEARCH_1,
   TABLE1.SEARCH_2

FROM      TABLE1,
          TABLE2;

CREATE PUBLIC SYNONYM NEW_VW;
DROP PUBLIC SYNONYM NEW_VIEW_VW;
CREATE PUBLIC SYNONYM NEW_VIEW_VW;
GRANT SELECT ON NEW_VIEW_VW;

1 个答案:

答案 0 :(得分:0)

视图需要5列,而select子句只有4列

试试这个:

CREATE OR REPLACE FORCE VIEW NEW_VIEW_VW
(
   URL,
   ORGANISATION,
   CATEGORY,
   SEARCH_1,
   SEARCH_2
)
AS
  SELECT DISTINCT
      TABLE1.SERV_URL,
      TABLE2.ORGANISATION,
      'xyz' category            ---- this col is missing
      TABLE1.SEARCH_1,
      TABLE1.SEARCH_2
 FROM TABLE1,
      TABLE2;

你还需要一个where子句来加入2个表吗?