1,执行如下代码即可实现递归查询:
delimiter //
CREATE FUNCTION `getParLst`(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(id) INTO sTempChd FROM treeNodes where FIND_IN_SET(pid,sTempChd)>0;
END WHILE;
RETURN sTemp;
END
//
2,如果有报错,请查询log_bin
例如:
SHOW VARIABLES LIKE ‘log_bin_trust_function_creators‘;
解决方法, 在mysql中执行如下语句:
SET GLOBAL log_bin_trust_function_creators=TRUE;
再查看
SHOW VARIABLES LIKE ‘log_bin_trust_function_creators‘;
OK解决!