今天用命令創建函數,
報錯
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)
原因是:
當二進制日志啟用后,這個log_bin_trust_function_creators變量就會啟用。它控制是否可以信任存儲函數創建者,不會創建寫入二進制日志引起不安全事件的存儲函數。如果設置為0(默認值),用戶不得創建或修改存儲函數,除非它們具有除CREATE ROUTINE或ALTER ROUTINE特權之外的SUPER權限。 設置為0還強制使用DETERMINISTIC特性或READS SQL DATA或NO SQL特性聲明函數的限制。 如果變量設置為1,MySQL不會對創建存儲函數實施這些限制。 此變量也適用於觸發器的創建
所以需要加一條命令
set global log_bin_trust_function_creators=TRUE; -- 設置, delimiter ;; CREATE FUNCTION concatFeatureJson(v_status tinyint, v_column_json VARCHAR(25)) RETURNS varchar(255) begin declare v_sql varchar(2000); SELECT group_concat(concat('JSON_EXTRACT(',v_column_json,',','\'.$',feature_short_from_name,'\') ',feature_short_from_name)) into v_sql from feature_space where status = v_status ; RETURN v_sql; end ;; delimiter ;