MySQL 查询所有子级函数

时间:2023-03-09 20:16:20
MySQL 查询所有子级函数

BEGIN
  DECLARE sChildList VARCHAR(4000);
  DECLARE sChildTemp VARCHAR(4000);
  SET sChildTemp =cast(rootId as CHAR);
  WHILE sChildTemp is not null
  DO
    IF (sChildList is not null) THEN
      SET sChildList = concat(sChildList,',',sChildTemp);
    ELSE
      SET sChildList = concat(sChildTemp);
    END IF;
    SELECT group_concat(id) INTO sChildTemp FROM xx_area WHERE FIND_IN_SET(parent, sChildTemp) > 0;
  END WHILE;
  RETURN sChildList;
END

select getAreaAllChildList(651) areaIds