我们如何在where子句中调用存储过程 [英] how can we call store procedure in where clause
问题描述
如何在where子句中调用MySQL过程?
How can I call a MySQL procedure in where clause?
在示例中,demo
是表名get_name()
是函数,而1
是参数(id).
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))
推荐答案
您应该使用函数而不是过程.一个过程返回一个(一个或多个)结果集(表),而一个函数返回一个值.
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.
如果在子句中使用函数,如果它们包含数据库中的select子句,则应三思而后行,因为这可能会导致查询优化器无法优化查询路径的情况,从而导致序列化查询和性能下降.如果数据量很小,或者您对可能的性能影响感到满意,则可以进行此操作.
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.
这篇关于我们如何在where子句中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!