Difference between Function and Procedure


Function

Function, in computer programming language context, a set of instructions which takes some input and performs certain tasks. In SQL, a function returns a value.

Procedure

Procedure, as well, is a set of instructions which takes input and performs certain task. In SQL, procedure does not return a value. In java, procedure and functions are same and also called sub-routines.

Following are the important differences between SQL Function and SQL Procedure.

Sr. No.KeyFunctionProcedure
1DefinitionA function is used to calculate result using given inputs.A procedure is used to perform certain task in order.
2CallA function can be called by a procedure.A procedure cannot be called by a function.
3DMLDML statments cannot be executed within a function.DML statements can be executed within a procedure.
4SQL, QueryA function can be called within a query.A procedure cannot be called within a query.
5SQL, CallWhenever a function is called, it is first compiled before being called.A procedure is compiled once and can be called multiple times without being compiled.
6SQL, ReturnA function returns a value and control to calling function or code.A procedure returns the control but not any value to calling function or code.
7try-catchA function has no support for try-catchA procedure has support for try-catch blocks.
8SELECTA select statement can have a function call.A select statemnt can't have a procedure call.
9Explicit Transaction HandlingA function can not have explicit transaction handling.A procedure can use explicit transaction handling.
raja
Published on 28-Nov-2019 11:29:50
Advertisements