Pan Kaj
Pan Kaj

Reputation: 25

how can we call store procedure in where clause

How can I call a MySQL procedure in where clause?

In the example demo is a table name get_name() is a function and 1 is a parameter (id) .

select * from demo where name = (select name from call get_name(1))

Upvotes: 0

Views: 1261

Answers (1)

slaakso
slaakso

Reputation: 9080

You should use a function instead of a procedure. A procedure returns a (one or multiple) result sets (tables), whereas a function returns a single value.

You should think twice before using functions in where-clause, if they contain select clauses from the database, as it may lead into situation where the query optimizer unable to optimize the query path resulting serialized queries and poor performance. If the data amount is small or you are ok with the possible performance hit, this would work.

Upvotes: 2

Related Questions