首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MySql 中查询树形构造的全部子项列表 Function

2012-08-25 
MySql 中查询树形结构的全部子项列表 Function不包含当前节点的Function?CREATEFUNCTION `linkPositionId`

MySql 中查询树形结构的全部子项列表 Function

不包含当前节点的Function

?

CREATE  FUNCTION `linkPositionId`(`nodeId` varchar(200)) RETURNS varchar(500) CHARSET utf8BEGINdeclare tmpPositionId varchar(100);declare positionIdStr  varchar(500);set positionIdStr = '';select LEADER_POSITION_ID,POSITION_ID into nodeId,tmpPositionId from HRM_POSITION where POSITION_ID = nodeId;while nodeId is not null doselect LEADER_POSITION_ID,POSITION_ID into nodeId,tmpPositionId from HRM_POSITION where POSITION_ID = nodeId;set positionIdStr = concat('$',tmpPositionId,'$',positionIdStr);end while;return positionIdStr;END;

?

包含当前节点的Function

?

CREATE FUNCTION `linkPositionIdIncludeSelf`(`nodeId` varchar(200)) RETURNS varchar(500) CHARSET utf8BEGINdeclare tmpPositionId varchar(100);declare positionIdStr  varchar(500);set positionIdStr = '';while nodeId is not null doselect LEADER_POSITION_ID,POSITION_ID into nodeId,tmpPositionId from HRM_POSITION where POSITION_ID = nodeId;set positionIdStr = concat('$',tmpPositionId,'$',positionIdStr);end while;return positionIdStr;END;

?

热点排行