码迷,mamicode.com
首页 > 其他好文 > 详细

递归存储过程

时间:2016-04-05 00:21:28      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

select id from oc_groups where FIND_IN_SET(id, getChildLst(23));

select id from oc_groups where FIND_IN_SET(id, getChildLst(9))

CREATE FUNCTION `getChildLst`(rootId INT)
RETURNS varchar(1000)
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 oc_groups where FIND_IN_SET(parentid,sTempChd)>0;
END WHILE;
RETURN sTemp;
END

show function STATUS

drop function getChildLst

delete from oc_groups where id>9

递归存储过程

标签:

原文地址:http://www.cnblogs.com/a963383404/p/5353289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!