mysql 递归查询

select *from k_type where FIND_IN_SET(pid,get_child_list('10'));

-- GROUP_CONCAT(id)

delimiter $$ 
-- drop function if exists get_child_list$$ 
create function get_child_list(in_id varchar(10)) returns varchar(1000) 
begin 
declare ids varchar(1000) default ''; 
declare tempids varchar(1000); 

set tempids = in_id; 
while tempids is not null do 
set ids = CONCAT_WS(',',ids,tempids); 
select GROUP_CONCAT(id) into tempids from k_type where FIND_IN_SET(pid,tempids)>0; 
end while; 
return ids; 
end 
$$ 
delimiter ;


-- 如果出现错误就执行
set global log_bin_trust_function_creators=TRUE;

简单记录 首先最开始是查询的语句 下面是一个函数方法 执行后会生成 当我们执行的时候出现错误要修改参数  下面set是临时修改配置

 

    1. 在mysql数据库中执行以下语句 (临时生效,重启后失效)
      set global log_bin_trust_function_creators=TRUE;

    2. 在配置文件/etc/my.cnf的[mysqld]配置log_bin_trust_function_creators=1  

posted @ 2022-04-14 12:59  热心居民  阅读(245)  评论(0)    收藏  举报