MySQL Forums
Forum List  »  Stored Procedures

Re: Path of entry in hierarchical table
Posted by: Glenn Thomas Hvidsten
Date: May 16, 2012 08:45AM

Thanks for that link. It seems I forgot a "DO" at the end of my WHILE.
That changed the error message into "you cannot return a result set from a function" (or something like that).

I then changed the inner SELECT statement to a "SELECT INTO" and now it seems to work the way I want it to. Thanks a lot for you help! :D

Here's the final SQL:


DELIMITER //
CREATE FUNCTION ItemPath (itemID varchar(36))
RETURNS varchar(4096) DETERMINISTIC
BEGIN

SET @id := itemID, @path := '/';

WHILE @id != '00000000-0000-0000-0000-000000000000' DO
SELECT ParentID, CONCAT('/', Name, @path) INTO @id, @path FROM Items WHERE ID = @id;
END WHILE;

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.