开发者

Return array in stored function

开发者 https://www.devze.com 2023-03-29 04:03 出处:网络
I am trying to use the result of a stored function in a WHERE statement in MySQL (5.x), but it fails because in the function I am selecting values from a table into an INT variable and开发者_如何学运维

I am trying to use the result of a stored function in a WHERE statement in MySQL (5.x), but it fails because in the function I am selecting values from a table into an INT variable and开发者_如何学运维 then returning them/it, which obviously doesn't work if the SELECT returns more than 1 row. I've tried returning a TABLE (as I understood TABLE means array in MySQL) but that didn't work either.

Is there any way that I could do something like:

SELECT ID FROM myTable WHERE ID IN my_function(params);

Thank you.


This cannot be done...

First, you cannot use a stored function to return multiple results - you would need to use a stored procedure.

The MySQL docs state:

Statements that return a result set can be used within a stored procedure but not within a stored function.

Second, you cannot use a stored procedure in a query - see this SO question.

Have you considered using 'HAVING ...' at the end of your query?

0

精彩评论

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