MySQL Forums
Forum List  »  Stored Procedures

Re: Path of entry in hierarchical table
Posted by: Rick James
Date: May 13, 2012 11:32AM

Something like...

DELIMITER //
CREATE STORED FUNCTION GetPath(_id INT UNSIGNED)
DETERMINISTIC
BEGIN
SET @id := _id, @path := '/';
WHILE (@id != 0)
SELECT @id := ParentID, @path := CONCAT('/', Name, @path) FROM tbl WHERE ID = @id;
RETURN @path;
END;
//
DELIMITER ;

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.