Declare variable inside a function
I've got some simple code that I can't seem to get to compile. Basically, I've got a function that will return an integer. I've tried to declare the return variable as the first statement inside the BEGIN..END block of the function. But, it does not compile and I can't work out why.
(I've reduced the query down to a very simple level substituting an integer for the subquery that I will be using once this code compiles.)
CREATE FUNCTION fn_GetYearAlbumRank(parmAlbumID INT, parmYear INT)
RETURNS INT
BEGIN
DECLARE retval INT;
SELECT 5 INTO retval;
RETURN retval;
END;
I get the following error (it doesn't seem to like the declare statement):
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT' at line 4
Subject
Views
Written By
Posted
Declare variable inside a function
59813
June 14, 2007 02:06AM
16371
June 14, 2007 05:07AM
9622
June 14, 2007 12:24PM
6962
December 28, 2008 11:49PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.