difference between store procedures and functions
Functions can't modify anything and must have at least one parameter. They also have to return a result. Stored procedures don't need a parameter, may modify database objects, and don't have to return a result.
Stored procedures are used to connect SQL queries in a transaction and to communicate with the outside world.
-
-
The function must return a value but in Stored Procedure it is optional. Even a procedure can return zero or n values.
-
Functions can have only input parameters for it whereas Procedures can have input or output parameters.
-
Functions can be called from Procedure whereas Procedures cannot be called from a Function.
12345678910111213<br>The
procedure
allows
SELECT
as
well
as
DML(
INSERT
/
UPDATE
/
DELETE
) statement
in
it whereas
Function
allows
only
SELECT
statement
in
it.
Procedures cannot be utilized
in
a
SELECT
statement whereas
Function
can be embedded
in
a
SELECT
statement.
Stored Procedures cannot be used
in
the SQL statements anywhere
in
the
WHERE
/
HAVING
/
SELECT
section
whereas
Function
can be.
Functions that
return
tables can be treated
as
another rowset. This can be used
in
JOINs
with
other tables.
Inline
Function
can be though
of
as
views that take parameters
and
can be used
in
JOINs
and
other Rowset operations.
An exception can be handled
by
try-catch block
in
a
Procedure
whereas try-catch block cannot be used
in
a
Function
.
We can use Transactions
in
Procedure
whereas we can't use Transactions
in
Function
.<br>
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现