PL / SQL:使用编译错误创建的函数

时间:2014-09-25 18:24:09

标签: sql function plsql

我正在试图弄清楚为什么我会收到编译错误

CREATE OR REPLACE FUNCTION Get_balance_due
(order_id_f NUMBER)
RETURN NUMBER
AS 
balance_due_f NUMBER;
BEGIN
SELECT SUM(total_amount) INTO balance_due_f 
FROM order_lines, orders
WHERE order_id_f = order_line.order_id;
RETURN balance_due_f;
End;

错误是

LINE/COL  ERROR  
7/1  PL/SQL: SQL Statement ignored  
9/20  PL/SQL: ORA-00918: column ambiguously defined 

我尝试进行常规选择查询并且有效

SELECT SUM(total_amount)
FROM order_lines, orders
WHERE order_lines.order_id = orders.order_id and orders.order_id = 12

该函数应该为所需的order_id执行数量的和,并将其返回...

错误消息为:使用编译错误创建的功能

1 个答案:

答案 0 :(得分:1)

每当出现此错误时,请尝试完全限定您使用的列。

而不是order_id_f = order_line.order_id尝试TABLENAME.order_id_f = order_line.order_id

请参阅:http://www.dba-oracle.com/t_ora_00918_column_ambiguously_defined.htm