各位用户为了找寻关于mysql 使用存储过程实现树节点的获取方法的资料费劲了很多周折。这里教程网为您整理了关于mysql 使用存储过程实现树节点的获取方法的相关资料,仅供查阅,以下为您介绍关于mysql 使用存储过程实现树节点的获取方法的详细内容

如图:

表数据

这样的一棵树,如何获取“高寅瑞”下的所有节点(一条sql语句是肯定搞不定的)

通过存储过程来写

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 delimiter // create function `getchildlst`(rootid int)   returns varchar(1000) reads sql data   begin  declare stemp varchar(1000);    declare stempchd varchar(1000);    set stemp = '$';    set stempchd =cast(rootid as char);    while stempchd is not null do    set stemp = concat(stemp,',',stempchd);    select group_concat(id) into stempchd from document_file_name where find_in_set(pid,stempchd)>0;    end while;    return stemp;   end //

创建如上存储过程

? 1 select * from document_file_name where find_in_set(id, getchildlst(1));

总结

到此这篇关于mysql 使用存储过程实现树节点的获取的文章就介绍到这了,更多相关mysql 存储过程树节点获取内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

原文链接:https://blog.csdn.net/xcc_2269861428/article/details/106529796