0
What is the difference between function and stored procedure
What is the difference between function and stored procedure
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 |