梅州建设工程交易中心网站,广东培训seo,巩义网站建设方案书,如何查看网站域名一、说明
由于Mysql不像oracle一样支持树状查询#xff0c;需要用户自行处理#xff0c;本文记录了一种常见的通过自定义函数的方式进行mysql树状查询的方法#xff0c;以及使用的注意事项。
二、函数
CREATE DEFINERrootlocalhost FUNCTION get_child_menus(in_pid varc…一、说明
由于Mysql不像oracle一样支持树状查询需要用户自行处理本文记录了一种常见的通过自定义函数的方式进行mysql树状查询的方法以及使用的注意事项。
二、函数
CREATE DEFINERrootlocalhost FUNCTION get_child_menus(in_pid varchar(64)) RETURNS varchar(10000) CHARSET utf8mb4
BEGINdeclare ids varchar(10000) default ;declare tempids varchar(10000);set tempids in_pid;while tempids is not null doset ids CONCAT_WS(,,ids,tempids);select GROUP_CONCAT(id) into tempids from tbl_menu where FIND_IN_SET(pid,tempids)0;end while;return ids;
END三、使用
select * from tbl_menu where find_in_set(id, get_child_menus(root_menu_id_0000000));四、注意事项
函数使用了GROUP_CONCAT函数聚合菜单id有可能会存在结果超长被截取的情况可以使用如下方法处理
SET group_concat_max_len556809;