What is the difference between function and stored procedure?

0 votes
116 views
Shikhar Arora asked 07-Dec-2019 in Technology by Shikhar Arora

What is the difference between function and stored procedure

1 Answer

0 votes
Sangsaptak Pal answered 10 days ago by Sangsaptak Pal

These are basically used in SQL. Function is compiled and executed every time it is called. It cannot modify the data received as parameter and it must return a value. On the other hand, the stored procedure is a pre-compiled object as it gets compiled for the first time and its complied format gets stored well. When it is called, it just gets executed.

Function Stored Procedure
It always returns a value It will not return a value
It has only input parameters It can have both input and output parameters
Functions can be called from procedures Procedures cannot be called from function
Transactions cannot be used here Transactions can be used here
Exceptions cannot be handled by try-catch block Exceptions can be handled by try-catch block
It can be used in SELECT statement It cannot be used in SELECT statement