DROP PROCEDURE IF EXISTS getResAlisa;
DELIMITER $$
CREATE PROCEDURE getResAlisa(IN resid varchar(255), OUT path TEXT)
BEGIN
DECLARE catname VARCHAR(255);
DECLARE temppath TEXT;
DECLARE tempparent VARCHAR(255);
SET max_sp_recursion_depth = 255;
SELECT c_resalias, c_pid FROM t_restree WHERE c_resid=resid INTO catname, tempparent;
IF tempparent IS NULL
THEN
SET path = catname;
ELSE
CALL getResAlisa(tempparent, temppath);
SET path = CONCAT(temppath, '/', catname);
END IF;
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS getResAlisa;
DELIMITER $$
CREATE FUNCTION getResAlisa(cat_id VARCHAR(255)) RETURNS TEXT DETERMINISTIC
BEGIN
DECLARE res TEXT;
CALL getResAlisa(cat_id, res);
RETURN res;
END$$
DELIMITER ;
弄好了 ,写了一个存储过程,写了一个函数,终于查出来了,参考的是
https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query