MySQL存储过程与函数,何时使用? [英] MySQL stored procedure vs function, which would I use when?
问题描述
我正在查看MySQL存储过程和函数.真正的区别是什么?
I'm looking at MySQL stored procedures and function. What is the real difference?
它们似乎很相似,但是一个功能有更多的局限性.
They seem to be similar, but a function has more limitations.
我可能是错的,但是似乎存储过程可以完成所有工作,而存储函数可以完成更多工作.为什么/何时使用过程与函数?
I'm likely wrong, but it seems a stored procedure can do everything and more a stored function can. Why/when would I use a procedure vs a function?
推荐答案
您不能将存储过程与普通SQL混合使用,而对于存储功能则可以.
You can't mix in stored procedures with ordinary SQL, whilst with stored function you can.
例如如果get_foo()
是过程,则SELECT get_foo(myColumn) FROM mytable
无效,但是如果get_foo()
是函数,则可以这样做.其代价是功能比过程具有更多的局限性.
e.g. SELECT get_foo(myColumn) FROM mytable
is not valid if get_foo()
is a procedure, but you can do that if get_foo()
is a function. The price is that functions have more limitations than a procedure.
这篇关于MySQL存储过程与函数,何时使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!