I am trying to create a simple custom function in MySQL that takes 2 values (id int, currencyValue double), looks up a value in another table based on the id and returns the currencyValue*rate.
Here is my psuedo-code that is not getting me anywhere near this. There is also a surprising lack of examples of this on Google.
DROP FUNCTION IF EXISTS ConvertCurrency
DROP FUNCTION IF EXISTS F_ConvertCurrency //
CREATE FUNCTION F_ConvertCurrency(PID INT, C_VALUE DOUBLE)
RETURNS DOUBLE
BEGIN
DECLARE Currency_Rate DOUBLE;
SET Currency_Rate = SELECT `Rate` FROM `Currencies` WHERE `ID` = PID;
RETURN Currency_Rate*C_VALUE;
END;//
I am getting the 'there is an error in your code near...' which helps me none. I have seen other examples of functions with the DELMITER keyword but have no idea what this means.