ORA 00918-列明确定义的错误 [英] ORA 00918- Column ambiguosly defined error
本文介绍了ORA 00918-列明确定义的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Oracle数据库中有两个表.
There are two tables in my Oracle database.
第一个表是(客户)-
customer_id Customer_name Customer_age Customer_address salary
103 Giriraj Rathi 22 Kolkata 12000
100 Subir Adhikari 22 Bolpur 10000
101 Rakesh Chatterjee 21 Tarkeshwar 8000
102 Jayanta Patra 20 Tarkeshwar 9000
104 Abhi Karmakar 22 Burdwan 8000
105 Mainak Manna 21 Burdwan 9000
106 Subho Gupta 20 Kolkata 10000
107 Aritra Das 23 Kolkata 7000
108 Pradip Paul 22 Kolkata 5000
109 Sourav Banerjee 22 Bolpur 9000
第二张表是(订单"):
Second table is (Orders):
Order_id Order_date customer_id amount
200 12-03-13 100 1100
201 09-05-13 101 1400
202 07-04-12 103 2500
204 29-05-13 104 2400
203 09-02-13 105 9000
205 18-06-13 106 2100
206 09-07-13 107 1600
207 18-05-13 108 2900
209 18-04-13 109 2400
现在,我想同时加入这两个表.所以我使用了查询:
Now I wanted to join both the tables. So I used the query:
select customer_id,
customer_name,
customer_address,
order_id,order_date,
amount
from customers,
orders
where customers.customer_id=orders.customer_id;
我搜索了该错误,并发现当SQL代码本身存在歧义时会发生这种情况,但是在这种情况下,我什么也看不到.
I Googled about the error and found this happens when there is ambiguity in the SQL code itself, but in this case I see nothing.
推荐答案
将表名/别名添加到这样的列总是一个好主意
It is always a good idea to add the table name/alias to the column like this
select c.customer_id,
c.customer_name,
c.customer_address,
o.order_id,
o.order_date,
o.amount
from customers c
inner join orders o on c.customer_id = o.customer_id
如果不这样做,那么数据库将不知道要采用哪一列,并且两个表都有一个名为customer_id
的列.
If you don't then the DB don't know which column to take and both tables have a column named customer_id
.
这篇关于ORA 00918-列明确定义的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文