CREATE DEFINER=`root`@`%` FUNCTION `queryOrgTree`(orgid INT) RETURNS varchar(5000) CHARSET utf8mb4
BEGIN
DECLARE oTemp varchar(5000);
DECLARE oTempId INT;
DECLARE oTempParent varchar(5000);
SET oTemp = '';
set oTempParent = '';
SET oTempId = orgid;
SELECT org_name into oTemp FROM cscp_org WHERE id = oTempId ;
SELECT parent_name into oTempParent FROM cscp_org WHERE id = oTempId ;
WHILE oTempId != 1
DO
SET oTemp = CONCAT(oTempParent,',',oTemp);
SELECT parent_id INTO oTempId FROM cscp_org WHERE id = oTempId ;
SELECT parent_name into oTempParent FROM cscp_org WHERE id = oTempId ;
END WHILE;
RETURN oTemp;
END
mysql 获取包含自身所有上级
最新推荐文章于 2024-07-03 03:35:12 发布