I am trying to write a function (MariaDB 10.2.9).
CREATE FUNCTION tesst (host VARCHAR(30)) RETURNS INT(4)
BEGIN
DECLARE hwid INT(4);
SELECT `id` INTO hwid FROM `hardware` WHERE `hostname` = host;
RETURN COALESCE(hwid, 'HWID not found');
END
Now I get the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3
I do not know what the error is.
EDIT: It works with
delimiter //
CREATE FUNCTION tesst (host VARCHAR(30)) RETURNS int(4)
BEGIN
DECLARE hwid INT(4);
SELECT `id` INTO hwid FROM `hardware` WHERE `hostname` = host;
RETURN COALESCE(hwid, 'HWID not found');
END //
delimiter ;
And set:
- Execute the following in the MySQL console:
SET GLOBAL log_bin_trust_function_creators = 1;
- Add the following to the mysql.ini configuration file:
log_bin_trust_function_creators = 1