MySQL自定义函数的方式
MySQL自定义函数的方式 MySQL 有两种方式自定义函数: 使用 Function 使用 Procedure MySQL的Function 开启函数功能 在使用之前,必须要确保 MySQL 已经开启了函数功能: -- 先查看函数功能是否开启: show variables like '%func%' ; -- 若是未开启则: SET GLOBAL log_bin_trust_function_creators = 1 ; -- 关闭则是: SET GLOBAL log_bin_trust_function_creators = 0 ; 使用 Function 的方法 function基本语法 -- 修改语句结束符为 $$ ,可以不使用这个方法 delimiter $$ create function fun ( value int ) returns int begin -- 声明局部变量,必须在函数体最开始声明 declare num int default 0 ; end -- 语句结束 $$ -- 修改语句结束符为 ; delimiter ; 创建一个函数 -------------------- demo1 ------------------- create function myfun2 ( x int , y int ) returns int begin