日期:2014-05-16 浏览次数:20734 次
drop PROCEDURE if EXISTS `getparentlst`; DELIMITER // CREATE PROCEDURE `getparentlst`(myid INTEGER) begin DECLARE sTemp INTEGER; DECLARE sLevel INTEGER; set sTemp=myid; set sLevel=1; CREATE TEMPORARY TABLE IF not EXISTS TEMP_父子关系表 ( `parentnode` int(11) ,-- 父节点 `node` int(11) , -- 节点 `isparent` int(11) , -- 是否为父节点 `level` int(11) -- 层级 ) ENGINE=MEMORY DEFAULT CHARSET=latin1 MAX_ROWS=10000; WHILE sTemp<>0 do insert into TEMP_父子关系表 SELECT t.parentnode,t.node,t.isparent,sLevel as `level` from viewparentchild t where node =sTemp and isparent=1; select parentnode into sTemp from 父子关系表 where node =sTemp and isparent=1; if(sTemp<>0) then set sLevel = sLevel +1; end if; end WHILE; select * from TEMP_父子关系表 view order by view.level desc; truncate table TEMP_父子关系表; end; //