Oracle 中的函数与过程 [英] Functions vs procedures in Oracle

查看:30
本文介绍了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?

  1. 如果我不能在 sql 语句中调用过程,好吧,我会写一个函数来做同样的工作.
  2. 过程不返回值,好吧,我将在任何 dml 操作后仅返回 sql%rowcount 或 1(success), 0(exception)
  3. 过程和函数都可以通过 OUT/IN OUT 参数将变量传递给调用环境

我听说主要区别在于性能,过程比函数快".但没有任何细节.

I heard that the main difference is in performance, 'procedures are faster than functions'. But without any detail.

提前致谢.

推荐答案

不同之处在于 - 一个函数必须在默认情况下返回一个值(任何类型),而在程序的情况下,你需要使用类似的参数OUTIN 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

  1. 一个函数总是使用 return 语句返回一个值,而一个过程可能通过参数返回一个或多个值,也可能根本不返回.尽管 OUT 参数仍然可以用于功能,它们是不可取的,也没有人可能发现需要这样做的情况.使用 OUT 参数限制函数在 SQL 语句中使用.

  1. 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. Using OUT parameter restricts a function from being used in a SQL Statement.

函数可用于典型的 SQL 语句,如 SELECTINSERTUPDATEDELETE, 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 中的函数与过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆