mysql函数的使用create function myfunction(...

use test   //必须在某个数据库下面创建

delimiter $

//创建

 CREATE FUNCTION myFunction(ln int, ls int)   //参数这里不能加default
    returns int      //注意这里是 returns  有加s 
    begin    
      declare num int default 0;     
      set num = ln + ls;
      return  num;
    end$

mysql> select myFunction(5,5) from dual$ 

//MySql DETERMINISTIC log_bin_trust_function_creators 自定义函数执行时报错

     解决办法有三种:

     1. 登录MySql客户端,执行: SET GLOBAL log_bin_trust_function_creators = 1;
     2.在登录MySQL服务器是,在服务启动时加上 “--log-bin-trust-function-creators=1 ”参数并设置为1。
     3.在my.ini(my.cnf)中的[mysqld]区段中加上 log-bin-trust-function-creators=1。

查看

 show function status;

删除

drop  function 函数名;

原文地址:https://www.cnblogs.com/sixiong/p/4438445.html