2016-04-27 79 views
2

我试图将MS SQL函数转换为Oracle函数,但是出现错误,我无法理解错误或者如何解决它们。将MS SQL函数转换为Oracle函数抛出错误

谁能帮助:

CREATE OR REPLACE FUNCTION ItemsSold 
(
    p_PrdID nvarchar2(50), 
    p_Cst nvarchar2(50) 
) 
RETURN Number 
AS 
v_Price NUMBER(18,2); 
BEGIN 

SELECT (Min(s.Price)*i.Qty) AS MinP into v_Price 
FROM   Customers AS c INNER JOIN 
         CustOrders AS o ON c.Name = o.Cust INNER JOIN 
         Sales AS i ON i.Order = o.Order INNER JOIN 
         Purchases AS s ON i.Item = s.Item 
WHERE  i.Item = p_PrdID AND o.Cust = p_Cst 
group by i.Qty) 

    RETURN v_Price; 



END; 

错误

Error(4,23): PLS-00103: Encountered the symbol "(" when expecting one of the following:  := .) , @ % default character The symbol ":=" was substituted for "(" to continue. 
Error(6,18): PLS-00103: Encountered the symbol "(" when expecting one of the following:  := .) , @ % default character The symbol ":=" was substituted for "(" to continue. 
Error(17,29): PLS-00103: Encountered the symbol "INNER" when expecting one of the following:  , ; for group having intersect minus order start union where connect 
+0

通过i.Qty组后无分号) – kevinsky

回答

4

开放式括号错误都与变量声明 - 在PL/SQL,不允许指定一个尺寸变量(所以让他们成为NVARCHAR2,你不能说NVARCHAR2(50))。

第三个错误与表名别名的Oracle语法有关 - Oracle使用关键字AS作为列别名(可选),但不允许将其用于表名别名。

在别名c之前(在错误消息指示的行上)删除NVARCHAR2的变量和关键字AS的大小规范并查看会发生什么情况。

祝你好运!

+0

arrgh,错过了你所看到的,哦,很多人眼中是一个更好的解决方案 – kevinsky

+0

将测试在明年30分钟,然后标出答案明显的问题,这对答复 –

+0

而更换“i.Qty组)”与“i.Qty组合”; –