getChildList:
BEGIN #声明两个局部变量 DECLARE sTemp VARCHAR(4000); DECLARE sTempChd VARCHAR(4000); #初始化局部变量 SET sTemp = ''; #调用cast函数将int转换为char SET sTempChd = rootId; #递归拼接 WHILE LENGTH(sTempChd) != 6 DO #存储每次递归结果 SET sTemp = sTempChd; #将参数作为pid,然后查询其子id,然后将子id作为pid, #查询以子id为pid的子id,依次循环下去,直到所有节点都为叶子节点 SELECT father_code INTO sTempChd FROM tmp_customer_org where code = sTempChd; -- code = sTempChd END WHILE; SET sTemp = sTempChd; RETURN sTemp; END
传入参数递归查询。
getParent:
BEGIN #声明两个局部变量 DECLARE sTemp VARCHAR(4000); DECLARE sTempChd VARCHAR(4000); #初始化局部变量 SET sTemp = ''; #调用cast函数将int转换为char SET sTempChd =rootId; #递归拼接 WHILE LENGTH(sTempChd) = 6 DO #存储每次递归结果 SET sTemp = sTempChd; #将参数作为pid,然后查询其子id,然后将子id作为pid, #查询以子id为pid的子id,依次循环下去,直到所有节点都为叶子节点 SELECT father_code INTO sTempChd FROM tmp_customer_org where code = sTempChd; END WHILE; RETURN sTemp; END