标签:function char 节点 har code div define mini eterm
#若存在则删除 DROP FUNCTION IF EXISTS `getBranchChildList`; #创建函数 入参VARCHAR(1000) 返回参数VARCHAR(1000) DELIMITER $$ CREATE #DEFINER=`root`@`localhost` #指定用户 FUNCTION `getBranchChildList`(rootId VARCHAR(1000)) RETURNS VARCHAR(1000) CHARSET utf8 DETERMINISTIC BEGIN #定义返回参数 DECLARE str VARCHAR(1000); #定义子id DECLARE cid VARCHAR(1000); #赋值 SET cid = rootId; #语法:while 条件 do 循环体 END WHILE; #循环递归 WHILE cid IS NOT NULL DO IF str IS NOT NULL THEN SET str = CONCAT(str, ‘,‘, cid); ELSE SET str = cid; END IF; SELECT GROUP_CONCAT(BRH_ID) INTO cid FROM im_branch WHERE FIND_IN_SET(BRH_PARENT_ID, cid) > 0; END WHILE; #返回结果eg: 00000,00001,00002..... RETURN str; END$$ DELIMITER ; eg: #查当前机构和子机构 SELECT b.BRH_ID,b.BRH_NAME FROM im_branch b WHERE FIND_IN_SET(BRH_ID, getBranchChildList(#session_usrBranchId) ) #查子机构 SELECT b.BRH_ID,b.BRH_NAME FROM im_branch b WHERE FIND_IN_SET(BRH_PARENT_ID, getBranchChildList(#session_usrBranchId) )
标签:function char 节点 har code div define mini eterm
原文地址:https://www.cnblogs.com/TianSuoMuLong/p/10059006.html