What is the difference between function and procedure in PL/SQL?

后端 未结 7 1056
日久生厌
日久生厌 2020-11-27 14:30

What is the difference between function and procedure in PL/SQL ?

7条回答
  •  无人及你
    2020-11-27 14:44

    Both stored procedures and functions are named blocks that reside in the database and can be executed as and when required.

    The major differences are:

    1. A stored procedure can optionally return values using out parameters, but can also be written in a manner without returning a value. But, a function must return a value.

    2. A stored procedure cannot be used in a SELECT statement whereas a function can be used in a SELECT statement.

    Practically speaking, I would go for a stored procedure for a specific group of requirements and a function for a common requirement that could be shared across multiple scenarios. For example: comparing between two strings, or trimming them or taking the last portion, if we have a function for that, we could globally use it for any application that we have.

提交回复
热议问题