56,678
社区成员
发帖
与我相关
我的任务
分享
DROP FUNCTION GetParentName;
CREATE FUNCTION `GetParentName`(`nodeId` int) RETURNS varchar(400) CHARSET utf8
BEGIN
DECLARE parentId INT;
DECLARE parentName VARCHAR(400);
DECLARE pId INT;
DECLARE num INT;
SET parentId = 99999;
SET parentName = '';
SET pId = `nodeId` ;
select count(1) INTO num from niche_intentresources where ID = pId;
if num = 0 then set parentId = 0;
else
select ParentID INTO parentId from niche_intentresources where ID = pId;
select `Title` INTO parentName from niche_intentresources where ID = pId;
end if;
WHILE parentId <> 0 DO
set pId = parentId;
select ParentID INTO parentId from niche_intentresources where id = pId;
select CONCAT_WS('-', `Title`, parentName) INTO parentName from niche_intentresources where ID = pId;
END WHILE;
RETURN parentName;
END