例子,mysql递归查询函数代码。
复制代码 代码示例:
#供应商类型递归查询函数
drop function if exists getChildLst_SupplierType ;
CREATE FUNCTION getChildLst_SupplierType(codeId varchar(25))
RETURNS varchar(1000)
BEGIN
DECLARE sTemp VARCHAR(1000);
DECLARE sTempChd VARCHAR(1000);
declare rootId varchar (200);
SET sTemp = '$';
#SET sTempChd =cast(codeId as CHAR);
select PATRIARCHYCODE into rootId from TB_FPTS_COMMON_SUPPLIERTYPE where SUPPLIERTYPE_CODE =sTempChd;
SET sTempChd=rootId;
WHILE sTempChd is not null DO
SET sTemp = concat(sTemp,',',sTempChd);
SELECT group_concat(SUPPLIERTYPE_CODE) INTO sTempChd FROM TB_FPTS_COMMON_SUPPLIERTYPE where FIND_IN_SET(PATRIARCHYCODE,sTempChd)>0;
END WHILE;
RETURN sTemp;
END
;
mysql递归查询树形叶子
MySQL 递归查询当前节点子节点
mysql递归查询实现方法
MySQL存储过程递归调用实例