Board logo

标题: mysql创建自定义函数 [打印本页]

作者: look_w    时间: 2019-4-18 16:49     标题: mysql创建自定义函数

DELIMITER $$
CREATE FUNCTION `new_function` ()
RETURNS INTEGER
BEGIN
RETURN 1;
END


红色句子很关键

delimiter




为命令终止符号,代替分号,因为分号在begin...end中会用到;

否则;号部分要报错。

出错信息大致类似:
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
建立不了函数,是未开启功能:
在mysql中启动函数创建开关:
mysql>set global log_bin_trust_function_creators=1;




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0