I personally will not follow strict rules. Of course, at the development stages, you want to quickly change your queries so that I can embed them.
I will move on to stored procedures later, because they offer the following two benefits. I am sure that there are more of them, but these two will defeat me.
1 / Stored procedures group data and code to process / retrieve this data at one point. This greatly simplifies the life of your database administrator (provided that your application is significant enough to guarantee DBAs), as they can be optimized based on known factors.
One of the big DBA errors is special queries (especially clowns who don’t know what a full table scan is). Database administrators prefer to have good consistent queries that can tune the database.
2 / Stored procedures may contain the logic that is best left in the database. I saw stored procs in DB2 / z with many dozens of lines, but all the client needs to encode is a single line, for example "give me this list."
Since the logic for "this list" is stored in the database, database administrators can change the way they are stored and retrieved as they wish without compromising or changing the client code. This is similar to encapsulation, which has made object-oriented languages more "clean" than the previous ones.
source share