Mysql sees the ';' delimiters in the function and breaks your CREATE FUNCTION
statement.
To avoid this, change the delimiter before you define the function, and then change it back afterward:
Like:
DELIMITER //
-- your create function definition statement here
//
DELIMITER ;
As in your code the first ;
semicolon was found at line 8
, it tried to execute it the code up to the ';', and the syntax was invalid because it was incomplete (BEGIN
without END
).