MySQL stored procedure vs function, which would I use when?(MySQL 存储过程与函数,我将在什么时候使用?)
问题描述
我正在研究 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 存储过程与函数,我将在什么时候使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 存储过程与函数,我将在什么时候使用?
基础教程推荐
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在多列上分布任意行 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
