当前位置:首页 > 数据库 > Mysql

mysql用户自定义函数实例与部分问题解决方法

一、查看创建函数的功能是否开启: mysql show variables like '%func%'; +-----------------------------------------+-------+ | variable_name | value | +-----------------------------------------+-------+ | log_bin_trust_function_creators | on |

  一、查看创建函数的功能是否开启:

  mysql> show variables like '%func%';

  +-----------------------------------------+-------+

  | variable_name | value |

  +-----------------------------------------+-------+

  | log_bin_trust_function_creators | on |

  +-----------------------------------------+-------+

  1 row in set (0.02 sec)

  二、如果value处值为off,,则需将其开启。

  mysql> set global log_bin_trust_function_creators=1;

  use app02

  delimiter //

  mysql>drop function if exists `testhanshu`;

  create function `testhanshu`(`tustate` int)

  returns varchar(2000)

  begin

  declare oneaddr varchar(200) default '';

  declare alladdr varchar(2000) default '';

  declare done int default false;

  declare curl cursor for select utruename from tsys_user where ustate = tustate;

  declare continue handler for not found set done = 1;

  open curl;

  repeat

  fetch curl into oneaddr;

  if not done then

  set oneaddr = concat(oneaddr, ';');

  set alladdr = concat(alladdr, oneaddr);

  end if;

  until done end repeat;

  close curl;

  return alladdr;

  end;

  mysql>select testhanshu(1);

  在使用mysql自己定义的函数时,出现错误java.sql.sqlexception: 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)

  解决办法有三种:

  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。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐