What is the difference between function and stored procedure?

Asked 07-Dec-2019
Viewed 872 times

0

What is the difference between function and stored procedure


1 Answer


0

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.

FunctionStored Procedure
It always returns a valueIt will not return a value
It has only input parametersIt can have both input and output parameters
Functions can be called from proceduresProcedures cannot be called from function
Transactions cannot be used hereTransactions can be used here
Exceptions cannot be handled by try-catch blockExceptions can be handled by try-catch block
It can be used in SELECT statementIt cannot be used in SELECT statement