MySql stored procedure-4. Parameters

Source: Internet
Author: User


MySql stored procedure-4. Parameter-related links: MySql stored procedure-1. Basic knowledge of SQL stored procedure-1. Parameter classification parameters, same as programming, mySql stored procedures can also contain parameters. In the previous example, we did not use parameters. In the following example, we use parameters. MySql parameters are classified into three types: IN, OUT, INOUT, even the three types of parameters literally are also well understood: www.2cto.com -- IN: This is a default type, that is, if the parameter does not specify the type, the default type is IN. If the value is passed in, this value is provided for the stored procedure. In addition, the changes made to the stored procedure will not affect the passed parameters. -- OUT: This is the value that the stored procedure needs to pass OUT, that is, the stored procedure changes it to you and passes it back to the program that calls it. -- INOUT: combines the above two features, that is, the value can be passed to the stored procedure for use, and the stored procedure can also change this value to the program that calls it. 2. The Parameter definition parameter is defined as follows: MODE param_name param_type (param_size); MODE can be IN, OUT, INOUT; param_name is the parameter name; param_type is the type. Note that the name cannot be the same as that of the field in the table. Let's take a look at the following example: www.2cto.com

In this example, we input a parameter to the stored procedure. The parameter here is a string, we want to use this stored procedure to list records with input strings contained in the name field in the products table. Here, data is mainly used for transmission to stored procedures, so IN is used. The execution result is as follows: it is noted that the parameter passed to the GetAll stored procedure is a "ca" parameter. On this basis, we use the number of records as the data output from the stored procedure to the external for a look at the OUT usage. Keep the number of records in the output parameter totalNum. Here, a session variable is used as the output parameter. After the stored procedure is processed, the record speed is kept in @ totalRecords. Then we run select @ totalRecords and the output is 2.

Related Article

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.