SQL默认';'为单条语句结束符。
由于在创建自定义函数过程中需要多条SQL语句顺序执行,势必会用到';',若不在创建函数语句前声明语句结束符,则会报语法错误。
ERROR 1064 (42000) at line 7: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near ''
若mysql已开启函数功能,
SET GLOBAL log_bin_trust_function_creators=1;
否则报错:
ERROR 1418 (HY000) at line 4: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled
同时在create函数语句前及end后做以下说明:
-- 声明;;替换系统默认的;为语句结束符
DELIMITER ;;
CREATE FUNCTION ...
BEGIN
...;
...;
END
;;
-- 语句结束符
-- 恢复系统默认设置
DELIMITER ;
...