记录mysql创建function是遇到的问题:参考:MySQL 创建函数失败提示1418 - 落日长烟 - 博客园
创建mysql函数:
drop function if EXISTS getUnitChildList;
create function getUnitChildList(rootId BIGINT)
RETURNS varchar(2000)
begin
declare sChildList varchar(2000);
declare sChildTemp varchar(1000);
set sChildTemp = cast(rootId as char); -- 将rootId强转为字符
while sChildTemp is not null do
if(sChildList is not null ) then
set sChildList = concat(sChildList,',',sChildTemp);
else
set sChildList = concat(sChildTemp);
end if;
select group_concat(menu_id) into sChildTemp from sys_menu_info where find_in_set(parent_id,sChildTemp)>0;
end while;
return sChildList;
end;
执行报错:
> 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)
原因:创建函数功能关闭;
查看方式:执行以下语句
show variables like '%func%';
结果为:
说明该功能关闭;需要开启此功能:
set global log_bin_trust_function_creators=1;
再查看是否看启:
结果为以下,则说明成功
再次执行函数sql成功。