📜  函数和过程的区别

📅  最后修改于: 2021-09-12 11:21:31             🧑  作者: Mango

函数:
它是计算机程序设计的基本思想之一。它用于根据给定的输入计算某些内容。因此它的名字来自数学。函数可以是用户定义的或预定义的。函数程序具有执行某些特定任务或功能的代码块。

程序:
在编程一组特定的指令或命令时称为过程。依靠编程语言,它被称为过程、子例程、函数或子程序。

函数和过程的区别:

S.NO Function Procedure
1. A function deals with as an expression. Whereas a procedure does not deal with as an expression.
2. Function is used to calculate something from a given input. Hence it got its name from Mathematics. While procedure is the set of commands, which are executed in a order.
3. The function can be called by a procedure. But a procedure can not be called by a function.
4. In sql, inside the function we can not use the DML(Data manipulation language) commands such as Insert, Delete, Update. Here, in sql, inside the procedure we can use DML commands.
5. Functions can be called through sql queries. However, the procedure can’t be called through a sql query.
6. Each time functions are compiled when they are called. Whereas, procedures are compiled only once and can be called again and again as needed without being compiled each time.
7. The return statement of a function returns the control and function’s result value to the calling program. While the return statement of the procedure returns control to the calling program, it can not return the result value.
8. Function doesn’t support try-catch blocks. While it supports try-catch blocks.
9. Function can be operated in the SELECT statement. While it can’t be operated in the SELECT statement.
10. Function does not support explicit transaction handles. While procedure supports explicit transaction handles.