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 存储过程与函数,我将在什么时候使用?


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01