开发者

MySQL: create function that returns an array

CREATE Function getNearIds (myLocationLon double, myLocationLat double开发者_C百科) RETURNS WHAT

I just want to return an array of integers, after a long search: some say use Group_concat to make the list as a comma separated list then use find_in_set when calling the function. this works ok but in HQL (Hibernate query language) it doesn't.

so I need a clear way for this function to return an array of integers, what if i want to return a list of items from items table, is this possible.

I think this is very simple to do in Oracle DB or even SQL server. why is it very tough in MySQL.

please help.


Why not just use a stored procedure instead? You could simply have it return a result set that had rows with just one column.

Stored functions can't do what you want to do - well, I suppose you could do that group concat thing but why bother? Create the stored procedure and have it return the ints you want.

Something like:

CREATE PROCEDURE getNearIds 
     (myLocationLon double, myLocationLat double)
BEGIN
   # whatever your logic is to get the ids... 
   # e.g.,
   select id from locations where [whatever "near" means]
END
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜