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.