2

I'm trying to convert a MS SQL Function to Oracle Function, but I'm getting errors and I cannot understand what errors or how to fix them.

Can anyone help:

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;

Errors

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 
1
  • no semi colon after group by i.Qty) Commented Apr 27, 2016 at 19:37

1 Answer 1

4

The open-parenthesis errors have to do with the variable declarations - in PL/SQL it is not permitted to assign a size to variables (so let them be NVARCHAR2, you can't say NVARCHAR2(50)).

The third error has to do with Oracle syntax for table name aliases - Oracle uses the key word AS for column aliases (optional), but does not permit its use for table name aliases.

Remove the size specification for NVARCHAR2 for the variables and the key word AS before the alias c (on the lines indicated by the error messages) and see what happens.

Good luck!

Sign up to request clarification or add additional context in comments.

3 Comments

arrgh, missed the obvious issues you saw, oh well, many eyes is a better solution
Will test in next 30 mins and then mark answer, that's for replies
And replace "group by i.Qty)" with "group by i.Qty;"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.