MySQL stored procedure vs function, which would I use when?

Viewed 121160

I'm looking at MySQL stored procedures and functions. What is the real difference?

They seem to be similar, but a function has more limitations.

I'm likely wrong, but it seems a stored procedure can do everything and more than a stored function can. Why/when would I use a procedure vs a function?

6 Answers

Stored procedure can be called recursively but stored function can not

Beside the answer given above, I would like to add that

Function(s) can be used in combination with other function and expressions and also in a nested fashion (in short they can be used in very complex form form to get the job done what we wants).

Same thing can be implemented in procedure but in procedure we had to done all the work done inside that procedure, meaning in a monolithic fashion code. (Whereas in function(s) can be for every task; a new function can be implemented). So at the end we can get the task done by using a combination of different function.

Related