创建递归查询函数
CREATE FUNCTION `getChildLst`(rootId INT)
RETURNS varchar(1000)
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(MENU_ID) INTO sTempChd FROM SYS_MENU where FIND_IN_SET(PARENT_ID,sTempChd)>0;
END WHILE;
RETURN sTemp;
END
获取包含自身及孩子节点id
select getChildLst(1);
获取多级树节点内容
select * from SYS_MENU
where FIND_IN_SET(MENU_ID, getChildLst(1));