MySQL CREATE FUNCTION Syntax
Solution 1:
You have to override your ;
delimiter with something like $$
to avoid this kind of error.
After your function definition, you can set the delimiter back to ;
.
This should work:
DELIMITER $$
CREATE FUNCTION F_Dist3D (x1 decimal, y1 decimal)
RETURNS decimal
DETERMINISTIC
BEGIN
DECLARE dist decimal;
SET dist = SQRT(x1 - y1);
RETURN dist;
END$$
DELIMITER ;
Solution 2:
MySQL create function syntax:
DELIMITER //
CREATE FUNCTION GETFULLNAME(fname CHAR(250),lname CHAR(250))
RETURNS CHAR(250)
BEGIN
DECLARE fullname CHAR(250);
SET fullname=CONCAT(fname,' ',lname);
RETURN fullname;
END //
DELIMITER ;
Use This Function In Your Query
SELECT a.*,GETFULLNAME(a.fname,a.lname) FROM namedbtbl as a
SELECT GETFULLNAME("Biswarup","Adhikari") as myname;
Watch this Video how to create mysql function and how to use in your query
Create Mysql Function Video Tutorial