0% found this document useful (0 votes)
15 views1 page

Stored Procedure VS Function

Stored Procedures are pre-compiled and can return multiple values, while Functions must return a value and are compiled each time they are called. Procedures can execute DML statements and handle exceptions, whereas Functions can only execute SELECT statements and cannot manage transactions. Additionally, Functions can be used in SQL statements like SELECT, while Procedures cannot.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Stored Procedure VS Function

Stored Procedures are pre-compiled and can return multiple values, while Functions must return a value and are compiled each time they are called. Procedures can execute DML statements and handle exceptions, whereas Functions can only execute SELECT statements and cannot manage transactions. Additionally, Functions can be used in SQL statements like SELECT, while Procedures cannot.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

DIFFERENCE B/W SQL STORED PROCEDURE AND SQL FUNCTIONS

Stored Procedures are pre-compile objects which are compiled for first time and its compiled
format is saved which executes (compiled code) whenever it is called. But Function is compiled
and executed every time when it is called. For more about stored procedure and function refer
the articles Different types of Stored Procedure and Different types of Function.

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.

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.

You might also like