创建View Oracle MySQL时出错

时间:2017-07-22 08:22:19

标签: sql oracle-sqldeveloper

Create View ViewA AS

Select o.orderid, o.dishid, o.quantity, o.ordertime, o.deliveryaddress, d.dishid, r.description, r.location, c.firstname, c.lastname, c.phonenumber, c.address, c.city, c.state, c.zip

FROM Orders o

JOIN Dishes d On (o.dishid = d.dishid)

JOIN Customers c ON (o.customerid = c.customerid)

JOIN Restaurants r ON (d.restaurantid = r.restaurantid);

我应该创建一个这样的视图,但我不明白错误:

ORA-00957:重复的列名称 00957. 00000 - "重复列名称"

重复的列名称在哪里?

2 个答案:

答案 0 :(得分:1)

您必须为每列提供别名。

运行:

Create View ViewA AS Select o.orderid ORDER_ID, o.dishid ORDER_DISH_ID, o.quantity ORDER_QUANTITY, o.ordertime ORDER_TIME, o.deliveryaddress DELIVERY_ADDRESS, d.dishid DISH_ID, r.description RES_DESCRIPTION, r.location RES_LOCATION, c.firstname CUST_FIRSTNAME, c.lastname CUST_LASTNAME, c.phonenumber CUST_PHONE, c.address CUST_ADDRESS, c.city CUST_CITY, c.state CUST_STATE, c.zip CUST_ZIP FROM Orders o JOIN Dishes d On (o.dishid = d.dishid) JOIN Customers c ON (o.customerid = c.customerid) JOIN Restaurants r ON (d.restaurantid = r.restaurantid);

答案 1 :(得分:0)

您有ItemIDo.dishid - oracle将尝试同时调用d.dishid - 您需要为它们添加别名