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

3
  • 1
    Did you change the delimiter before that? You need to. To avoid ending the function at the first ; Commented Oct 23, 2017 at 19:17
  • What do you mean? Sorry I do not know what delimiter is / how I use it. Commented Oct 23, 2017 at 19:19
  • Search "delimiter" in this documentation. Read the explanatory text below the code example you will find. Commented Oct 23, 2017 at 19:21

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.