Functions vs procedures in Oracle(Oracle 中的函数与过程)
问题描述
谁能解释一下 Oracle 中函数和过程之间的主要区别是什么?如果我可以用函数做任何事情,为什么我必须使用过程?
can anybody explain what is the main difference between functions and procedures in Oracle? Why must I use procedures if I can do everything with functions?
- 如果我不能在 sql 语句中调用过程,好吧,我会写一个函数来做同样的工作.
- 过程不返回值,好吧,我将在任何 dml 操作后仅返回 sql%rowcount 或 1(success), 0(exception)
- 过程和函数都可以通过 OUT/IN OUT 参数将变量传递给调用环境
我听说主要区别在于性能,过程比函数快".但没有任何细节.
I heard that the main difference is in performance, 'procedures are faster than functions'. But without any detail.
提前致谢.
推荐答案
不同之处在于 - 一个函数必须在默认情况下返回一个值(任何类型),而在程序的情况下,你需要使用类似的参数OUT
或 IN OUT
参数获取结果.您可以在普通 SQL
中使用函数,而不能在 SQL
语句中使用过程.
The difference is- A function must return a value (of any type) by default definition of it, whereas in case of a procedure you need to use parameters like OUT
or IN OUT
parameters to get the results. You can use a function in a normal SQL
where as you cannot use a procedure in SQL
statements.
函数和过程之间的一些差异
Some Differences between Functions and Procedures
一个函数总是使用 return 语句返回一个值,而一个过程可能通过参数返回一个或多个值,也可能根本不返回.尽管
OUT
参数仍然可以用于功能,它们是不可取的,也没有人可能发现需要这样做的情况.使用OUT
参数限制函数在 SQL 语句中使用.
A function always returns a value using the return statement while a procedure may return one or more values through parameters or may not return at all.Although,
OUT
parameters can still be used in functions, they are not advisable neither are there cases where one might find a need to do so. UsingOUT
parameter restricts a function from being used in a SQL Statement.
函数可用于典型的 SQL 语句,如 SELECT
、INSERT
、UPDATE
、DELETE
, MERGE
,而过程不能.
Functions can be used in typical SQL statements like SELECT
, INSERT
, UPDATE
, DELETE
, MERGE
, while procedures can't.
函数通常用于计算,而过程通常用于执行业务逻辑.
Functions are normally used for computations where as procedures are normally used for executing business logic.
Oracle 提供了创建基于函数的索引"的规定提高后续 SQL 语句的性能.这适用于在查询的 where 子句中对索引列执行函数时.
Oracle provides the provision of creating "Function Based Indexes" to improve the performance of the subsequent SQL statement. This applies when performing the function on an indexed column in where clause of a query.
关于函数与函数的更多信息过程此处和这里.
More Information on Functions Vs. Procedures here and here.
这篇关于Oracle 中的函数与过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle 中的函数与过程


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