存储过程和用户​​定义函数之间的区别 [英] Difference between stored procedures and user defined functions

查看:136
本文介绍了存储过程和用户​​定义函数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释存储过程和用户​​定义函数之间的确切区别,以及在哪些上下文中有用的是什么。

Can anyone please explain what is the exact difference between stored procedures and user defined functions and in which context what is useful?

推荐答案

p>这是我总是记住:)

This is what i always keep in mind :)


  • 过程可以返回零或n值,而函数可以返回一个必须的值

  • 过程可以有输入/输出参数,而函数只能有输入参数。

  • 过程允许select和DML语句

  • 函数可以从过程调用,而不能从函数调用过程。

  • 异常可以通过try / catch块在一个过程中,而try-catch块不能在函数中使用。

  • 我们可以在过程中进行事务管理,而我们不能进入函数。 >
  • 程序不能在select语句中使用,而函数可以嵌入到select语句中。

  • UDF可以在WHERE / HAVING / SELECT section where as存储过程不能。

  • 返回表的UDF可以被视为另一个行集。

  • 内联UDF可以是带有参数的视图,可以在JOIN和其他Rowset操作中使用。

  • Procedure can return zero or n values whereas function can return one value which is mandatory.
  • Procedures can have input/output parameters for it whereas functions can have only input parameters.
  • Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
  • Functions can be called from procedure whereas procedures cannot be called from function.
  • Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
  • We can go for transaction management in procedure whereas we can't go in function.
  • Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
  • UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.
  • UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.
  • Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

http://www.codeproject.com/Tips/286539/Difference-between-stored-procedure-and-function

这篇关于存储过程和用户​​定义函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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