在使用MySQL數據庫時,有時會遇到MySQL函數不能創建的情況。下面就教您一個解決MySQL函數不能創建問題的方法,供您借鑑參考。
出錯信息大致類似:
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> show variables like '%func%';
- +---------------------------------+-------+
- | Variable_name | Value |
- +---------------------------------+-------+
- | log_bin_trust_function_creators | OFF |
- +---------------------------------+-------+
- 1 row in set (0.00 sec)
- mysql> set global log_bin_trust_function_creators=1;
- Query OK, 0 rows affected (0.00 sec)
- mysql> show variables like '%func%';
- +---------------------------------+-------+
- | Variable_name | Value |
- +---------------------------------+-------+
- | log_bin_trust_function_creators | ON |
- +---------------------------------+-------+
- 1 row in set (0.00 sec)mysql>
注意:在mysql環境中創建函數和過程時必須加入delimiter $$
和結束的$$ 否則會報語法錯誤。
delimiter $$
drop function getParamDescByValue;
create function getParamDescByValue(
in_sParamCode VARCHAR(64),
in_sParamValue VARCHAR(64)
) returns VARCHAR(255)
begin
DECLARE v_sTemp VARCHAR(255);
select param_desc into @v_sTemp from info_param where param_code = in_sParamCode and param_value = in_sParamValue;
return @v_sTemp;
end$$