Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What's the difference between stored procedure and functions?

user-image
Question added by ARUN KUMAR P V , Software developer & data base developer , KAMEDA INFO LOGICS PVT LTD
Date Posted: 2015/12/01
Muhammad Nagy
by Muhammad Nagy , Lead Software Engineer , OTS

  1. Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).
  2. Functions can have only input parameters for it whereas Procedures can have input/output parameters .
  3. Functions can be called from Procedure whereas Procedures cannot be called from Function.
  4. SP allows CRUD operations while function allows only SELECT
  5. Function can be used within SELECT statement while SP can't
  6. The most important feature of stored procedures over function is to retention and reuse the execution plan while in case of function it will be compiled every time.
  7. Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables
  8. Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.
  9. We can go for Transaction Management in Procedure whereas we can't go in Function.

Muhammad Jamshaid
by Muhammad Jamshaid , Warehouse Supervisor , FedEx Express

Hi,

The basic difference between function and stored procedure is that ,

>Function has only input parameter.Whereas,

>Stored-procedure can have input or output parameter.

>Function can be called from stored procedure.Whereas,

>Stored-procedure can not  be called from Function.

zahra mogies
by zahra mogies , Technical Support , Aljerasy group

Function can  be called from procedure and  must return a value

 

Deleted user
by Deleted user

A function can be used inline in SQL Statement if it returns a scalar value or can be joined upon if it returns a result set.

Gamal AbdelNasser Yossif
by Gamal AbdelNasser Yossif , Senior Backend Engineer , El Dokan

Basic Difference

 

Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).

 

 

 

Functions can have only input parameters for it whereas Procedures can have input/output parameters .

 

 

Functions can be called from Procedure whereas Procedures cannot be called from Function.

 

Advance Difference

 

Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.

 

 

Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.

 

 

Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.

 

 

The most important feature of stored procedures over function is to retention and reuse the execution plan while in case of function it will be compiled every time.

 

 

Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.

 

 

Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

 

 

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.

 

wissam Bekdash
by wissam Bekdash , Project Manager , Freelancer

Functions can have only input parameters but procedures can have input/output parameters . Function must take one input parameter but Stored Procedure may take o to many input parameters. function must return a value,while procedure it's not a must

syed syed
by syed syed , Senior software Engineer , Intel Technologies

Functions are the one which is developed by us with the help of java or .net codings but procedures are the protocols that is used with in built in function to execute a code or a program

Naveed Ahmed Mangi
by Naveed Ahmed Mangi , IT Administrator , Belfast General Trading

If we want to do certain repetitive tasks oroperations over our database within the same application and database  that is called Stored Procedures.

Functions are Database object that is being created for implementing or handling certain types of complex functionalities

Hussam Elgammal
by Hussam Elgammal , Information & Communication Technology Department Manager , Salalah Free Zone Company

Function takes one input parameter it is mandatory but Stored Procedure may take o to n input parameters.. Functions can be called from Procedure whereas Procedures cannot be called from Function

Abeer hussein
by Abeer hussein , Resource , Aspire - infotech

 

  • Functions can be called from procedure whereas procedures cannot be called from function.
  • Procedure can return zero or n values whereas function can return one value which is mandatory.

Muhammad Aoun
by Muhammad Aoun , Senior Software Engineer , TPS Private Limited

Stored Procedures are pre-compile objects which are compiled for first time and its compiled format is saved which executes whenever it is called. But Function is compiled and executed every time when it is called. 

More Questions Like This