Re: Path of entry in hierarchical table
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 ;
Subject
Views
Written By
Posted
2341
May 05, 2012 03:36PM
1327
May 06, 2012 11:56AM
1279
May 12, 2012 04:23AM
1187
May 12, 2012 11:02AM
1320
May 12, 2012 12:02PM
1419
May 13, 2012 09:53AM
1183
May 13, 2012 11:38AM
1329
May 13, 2012 11:32AM
1224
May 13, 2012 02:39PM
1280
May 14, 2012 07:47PM
1192
May 15, 2012 01:19AM
1220
May 16, 2012 07:24AM
Re: Path of entry in hierarchical table
1539
May 16, 2012 08:45AM
1146
May 15, 2012 11:27AM
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.