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; |