kristain

博客园 首页 新随笔 联系 订阅 管理

获取父IDs:

BEGIN
       DECLARE sTemp VARCHAR(1000);
       DECLARE sTempPar VARCHAR(1000);

       SET sTemp = '';
       SET sTempPar =childId;

       WHILE sTempPar is not null DO
         SET sTemp = concat(sTemp,',',sTempPar);
         SELECT group_concat(parentid) INTO sTempPar FROM t_runner_menu where parentid<>id and FIND_IN_SET(id,sTempPar)>0;
       END WHILE;
       RETURN sTemp;
END


参数:childId varchar(50)
回传类型:varchar(1000) CHARSET gbk

获取子IDs:

BEGIN
          DECLARE sTemp VARCHAR(1000);
          DECLARE sTempChd VARCHAR(1000);

          SET sTemp = '$';
         SET sTempChd =cast(rootId as CHAR);

         WHILE sTempChd is not null DO
            SET sTemp = concat(sTemp,',',sTempChd);
             SELECT group_concat(id) INTO sTempChd FROM  t_organization where FIND_IN_SET(parent_id,sTempChd)>0;
       END WHILE;
       RETURN sTemp;
END

参数:rootId INT
回传类型:varchar(1000) CHARSET gbk
posted on 2012-05-21 13:39  kristain  阅读(6527)  评论(0编辑  收藏  举报