أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
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.
Function can be called from procedure and must return a value
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.
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.
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
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
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.