【问题标题】:mysql function error in syntaxmysql函数语法错误
【发布时间】:2017-10-24 04:18:55
【问题描述】:

我正在尝试编写一个函数 (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

现在我收到以下错误:

#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 

我不知道错误是什么。

编辑: 它适用于

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 ;

并设置:

  1. 在 MySQL 控制台中执行以下命令:

SET GLOBAL log_bin_trust_function_creators = 1;

  1. 将以下内容添加到 mysql.ini 配置文件中:

log_bin_trust_function_creators = 1

【问题讨论】:

  • 你之前有没有改过分隔符?你需要。避免在第一个;处结束函数
  • 什么意思?抱歉,我不知道分隔符是什么/如何使用它。
  • this documentation 中搜索“分隔符”。阅读您将找到的代码示例下方的说明文本。

标签: mysql function syntax


【解决方案1】:

所以我做到了。 https://stackoverflow.com/a/26015334/8821276

  1. 在 MySQL 控制台中执行以下命令:

SET GLOBAL log_bin_trust_function_creators = 1;

  1. 将以下内容添加到 mysql.ini 配置文件中:

log_bin_trust_function_creators = 1

现在可以了,谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 2016-08-23
    • 2020-01-12
    • 2022-01-12
    • 2021-01-19
    相关资源
    最近更新 更多