MySQL函数写法
首先要查看数据库中是否存在次函数
查看数据库函数的命令
SHOW FUNCTION STATUS;
CREATE FUNCTION test (id CHAR(100)) RETURN INTEGER; 创建一个函数
BEGIN 开始
DECLARE
temp INTEGER; 声明一个变量
SELECT 做的查询语句
COUNT(*) INTO temp 将结果赋值给temp
FROM
demo_table
WHERE
id = id; 给定条件
RETURN temp; 返回结果temp
END 结束
若出现
[Err] 1418 - 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)
,需要执行如下语句:
set global log_bin_trust_function_creators=1;
注意:报错的话需要执行set global log_bin_trust_function_creators=TRUE;
造成这个问题的原因是主从设备的安全原因。