A stored procedure is a collection of user-defined SQL statements involving tasks of a specific table or other objects. You can call the stored procedure. A function is usually a database-defined method, it receives parameters and returns some type of values, and does not involve specific user tables.
Stored Procedures and functions have the following differences:
1) In general, the functions implemented by stored procedures must be more complex, while the functions implemented by functions are more targeted. Stored procedures are powerful and can be used to perform a series of database operations, including modifying tables. User-defined functions cannot be used to perform a group of operations to modify the global database status.
2) For stored procedures, parameters such as record sets can be returned, while functions can only return values or table objects. A function can return only one variable, while a stored procedure can return multiple variables. Stored procedure parameters can be IN, OUT, And INOUT, while functions can only have IN classes ~~ The stored procedure declaration does not require a RETURN type, but the RETURN type must be described during the function declaration. The function body must contain a valid RETURN statement.
3) stored procedures, you can use undefined functions, and do not allow built-in undefined functions in the User-Defined Function body.
4) The stored procedure is generally executed as an independent part (EXECUTE statement execution), and the function can be called as a part of the query statement (SELECT call ), because a function can return a table object, it can be located behind the FROM keyword in the query statement. Stored procedures are unavailable in SQL statements, but functions can be used.