sql代码
[code]select getParentIdList(3402)
视图
获取上级父集id函数代码
[code]CREATE DEFINER=`skip-grants user`@`skip-grants host` FUNCTION `getParentIdList`(rootId INT) RETURNS varchar(1000) CHARSET utf8mb4DETERMINISTICBEGINDECLARE fid INT default 0;DECLARE str varchar(1000) default rootId;WHILE rootId is not null doSET fid =(SELECT pid FROM t_space WHERE id = rootId);IF fid is not null THENSET str = concat(str, \',\', CAST(fid AS CHAR));SET rootId = fid;ELSESET rootId = fid;END IF;END WHILE;return str;END