【发布时间】: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 ;
并设置:
- 在 MySQL 控制台中执行以下命令:
SET GLOBAL log_bin_trust_function_creators = 1;
- 将以下内容添加到 mysql.ini 配置文件中:
log_bin_trust_function_creators = 1
【问题讨论】:
-
你之前有没有改过分隔符?你需要。避免在第一个
;处结束函数 -
什么意思?抱歉,我不知道分隔符是什么/如何使用它。
-
在this documentation 中搜索“分隔符”。阅读您将找到的代码示例下方的说明文本。