MySQL 函数的定义、使用

MySQL函数有且只有一个返回值
一、创建语法
create function 函数名(参数列表)returns 返回类型
begin
函数体
end

参数列表由两部分组成:
参数名 参数类型

二、调用语法
select 函数名(参数列表)

三、 示例
定义:
在这里插入图片描述
调用:
在这里插入图片描述
定义过程中可能出现错误:
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)
此时可以通过设置变量log_bin_trust_function_creators的值为1进行解决:
set global log_bin_trust_function_creators=1;

猜你喜欢

转载自blog.csdn.net/weixin_40315481/article/details/104214605