문제

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top