根據子節點找父節點函式,誰幫忙看下啥問題。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/186529.html
標籤:MySQL
上一篇:云服務器建站選擇
