SQL默認';'為單條語句結束符坟漱。
由于在創(chuàng)建自定義函數(shù)過程中需要多條SQL語句順序執(zhí)行,勢必會用到';'钧忽,若不在創(chuàng)建函數(shù)語句前聲明語句結束符胚泌,則會報語法錯誤省咨。
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已開啟函數(shù)功能肃弟,
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函數(shù)語句前及end后做以下說明:
-- 聲明;;替換系統(tǒng)默認的;為語句結束符
DELIMITER ;;
CREATE FUNCTION ...
BEGIN
...;
...;
END
;;
-- 語句結束符
-- 恢復系統(tǒng)默認設置
DELIMITER ;
...