--MYSQL Gets the current node and recursively all ancestor nodes--parameter description: Resultfield: Query return field, IDD to query the resource ID value, idfieldname ID field name, parentidfieldname ancestor ID field name, TableName table name, whether iscontainmyself contains its own drop procedure if EXISTS pro_getparentlist;create procedure pro_getparentlist (in Resultfield varchar (4000), in myID varchar (+), in idfieldname varchar (+), in parentidfieldname varchar (+), in TableName varchar (+), iscontainmyself int) begindrop table if exists tmpparent; CREATE TABLE tmpparent (temid varchar); set @tempParentId =myid; Set @myDoflag = 1; While @myDoflag >0 does set @ssss = CONCAT (' Select ', Parentidfieldname, ', COUNT (*) into @tempParentId, @myDoflag F Rom ', TableName, ' where ', idfieldname, ' = ', ' ', @tempParentId, ' ');p repare strSQL from @ssss; execute strSQL; deallocate prepare strSQL; if (@myDoflag >0) then sets @insertSql = CONCAT (' INSERT into tmpparent (temid) VALUES (', ' ' ", @tempParentId," ' ", ') '); Prepare preSql1 from @insertSql; Execute PRESQL1; deallocate prepare PRESQL1; End If;end while; IF (iscontainmyself=1) Theninsert into Tmpparent (temid) values (myID); END IF; Set @fieldSql =concat (' SELECT ', Resultfield), set @strsql = Concat (@fieldSql, ' from ', TableName, ' s ', ' inner join Tmppar Ent t on T.temid=s ", Idfieldname, ' order by S. ', Idfieldname, ' ASC ');p repare presql from @strsql; execute presql; End
MYSQL gets the current node and recursively all ancestor nodes