I was asked this question by the interviewer during the interview two days ago, and I did not say anything about it. It seems that I still need to summarize the database knowledge from time to time!
I found some information on the Internet and summarized it as follows:
First, the previous image:
Differences in Oracle
In SQL Server:
Essentially, there is no difference. Only functions are as follows: only one variable can be returned. The stored procedure can return multiple objects. Functions can be embedded in SQL and called in select, but stored procedures cannot. The essence of execution is the same.
There are many function restrictions, such as the use of temporary tables, the use of only table variables, and some functions are not available, but there are relatively few restrictions on stored procedures.
1. In general, the functions implemented by stored procedures must be more complex, while the functions implemented by functions are more targeted.
2. For stored procedures, parameters can be returned, while functions can only return values or table objects.
3. the stored procedure is generally executed as an independent part (Exec execution), and the function can be called as a part of the query statement (Select call), because the function can return a table object, therefore, it can be located behind the from keyword in the query statement.
4. when stored procedures and functions are executed, SQL manager will go to procedure cache to obtain the corresponding query statement. If no query statement exists in procedure cache, SQL manager compiles stored procedures and functions.
The execution plan is saved in procedure cache. After compilation, execute the execution plan in procedure cache, then, SQL Server will consider whether to save the plan in the cache based on the actual situation of each execution plan. The criterion is the possible frequency of this execution plan; the second is the cost of generating this plan, that is, the Compilation Time. The Plan saved in the cache does not need to be compiled during the next execution.
Most of the summary in SQL Server is applicable to Oracle. In the specific use process, the complexity and actual situation of the system implementation should also be checked. experienced DBAs should have been familiar with the use of the two. Please give me more advice when passing! Hoho