SQL错误:ORA-00918:列模糊定义

时间:2015-11-24 16:53:08

标签: sql oracle

请帮我看看我在这里做错了什么:

从命令行中的第1行开始出错 -

CREATE VIEW VW_ROUTE AS
  SELECT ROUTE_NAME
       , FARE
       , DESTINATION
       , ROUTE_ID
       , STOP_NAME
       , TERMINUS
       , NUMBER_OF_STOPS
  FROM STOPS S
    LEFT JOIN ROUTE R
        ON S.ROUTE_ID = R.ROUTE_ID
 WHERE NUMBER_OF_STOPS > ('1')
Error at Command Line : 5 Column : 10
Error report -
SQL Error: ORA-00918: column ambiguously defined
00918. 00000 -  "column ambiguously defined"
*Cause:    
*Action:

1 个答案:

答案 0 :(得分:5)

两个表中都有相同的列名。添加别名。

CREATE VIEW VW_ROUTE AS
SELECT ROUTE_NAME
       , FARE
       , DESTINATION
       , S.ROUTE_ID          -- ROUTE_ID exists in table STOPS/ROUTE
       , STOP_NAME
       , TERMINUS
       , NUMBER_OF_STOPS
FROM STOPS S
LEFT JOIN ROUTE R
  ON S.ROUTE_ID = R.ROUTE_ID
WHERE NUMBER_OF_STOPS > ('1');

好的做法是在所有出现时使用别名以避免含糊不清。