A stored procedure is a collection of user-defined series 1 sql statements that involve tasks involving specific tables or other objects and can be invoked by the user, while a function is usually a database defined method that takes parameters and returns a value of some type and does not involve a specific user table.
There are several differences between stored procedures and functions:
-
Generally speaking, the functions of stored procedures are more complex, while the functions of functions are more targeted. Stored procedures, powerful, can be performed including table modification 1 series of database operations; User-defined functions cannot be used to perform a set of operations that modify the state of the global database.
-
For stored procedures, parameters such as recordsets can be returned, while functions can only return values or table objects. A function can only return 1 variable; A stored procedure can return more than one. The parameters of the stored procedure can be of IN,OUT and INOUT3 types, while the function can only have IN class ~~ When the stored procedure is declared, the return type is not required, while the function declaration needs to describe the return type, and the function body must contain a valid RETURN statement.
-
Stored procedures. Non-deterministic functions can be used and are not allowed to be built into the body of user-defined functions.
-
Stored procedure 1 is typically executed as a separate part (EXECUTE statement), while the function can be called as part of the query (SELECT call). Since the function can return a table object, it can be placed after the FROM keyword in the query. Stored procedures are not available in SQL statements, but functions are.