0

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:

  1. Execute the following in the MySQL console:

SET GLOBAL log_bin_trust_function_creators = 1;

  1. Add the following to the mysql.ini configuration file:

log_bin_trust_function_creators = 1

Tobi
  • 31
  • 2
  • 5
  • 1
    Did you change the delimiter before that? You need to. To avoid ending the function at the first `;` – juergen d Oct 23 '17 at 19:17
  • What do you mean? Sorry I do not know what delimiter is / how I use it. – Tobi Oct 23 '17 at 19:19
  • Search "delimiter" in [this documentation](https://dev.mysql.com/doc/refman/5.7/en/create-procedure.html). Read the explanatory text below the code example you will find. – trincot Oct 23 '17 at 19:21

1 Answers1

0

So I did it. https://stackoverflow.com/a/26015334/8821276

  1. Execute the following in the MySQL console:

SET GLOBAL log_bin_trust_function_creators = 1;

  1. Add the following to the mysql.ini configuration file:

log_bin_trust_function_creators = 1

It works now, thank you!

Tobi
  • 31
  • 2
  • 5