Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need SQL functions when stored procedures can do all what SQL function does? [duplicate]

Please don't specify the differences between stored procedure and functions. Just want the reasons where functions have an advantage over stored procedures.

My understanding is that stored procedures works faster than functions and it can do all that a function can do so why do we need function in place?

I have read articles where it states that it can easily embedded in an select statement but that can be done in stored procedure as well (by writing the whole select statement in the stored procedure).

like image 360
Vahid Ahmed Avatar asked Nov 02 '25 12:11

Vahid Ahmed


1 Answers

A function can be used inline in SQL statements while stored procedures cannot.

like image 199
Racil Hilan Avatar answered Nov 04 '25 03:11

Racil Hilan