Differences between Mysql stored procedures and functions

Source: Internet
Author: User


Differences between Mysql stored procedures and functions stored procedures are a collection of user-defined SQL statements involving tasks of specific tables or other objects. You can call stored procedures, A function is usually a database-defined method. It receives parameters and returns some type of values without involving specific user tables. There are several differences between stored procedures and functions at www.2cto.com: 1) In general, the functions of stored procedures must be more complex, and the functions of 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.