MySQL stored procedure is a series of SQL statement sets, and its parameters can use IN, OUT and INOUT types. The following uses an example to illustrate the usage of stored procedures. The specific operations are as follows:
1. The first step is to create a database table. t_teacher, the SQL statement to create the database table:
create table t_teacher( id int(10), tno int(10), tname varchar(20), tsex varchar(2), tage int(2), taddr varchar(40) );
As shown below:
2. In the second step, after creating the database table, view the database table structure and view the database table data, as shown in the following figure:
3. The third step is to insert four pieces of data into the database table and view the database table data, as shown in the figure below:
4. The fourth step is to create the stored procedure query_count(). The stored procedure is to query the number of data, as shown in the following figure:
5. The fifth step is to call the stored procedure query_count(), as shown in the figure below:
6. Step six, after creating the stored procedure, after calling it, query the results, as shown in the following figure:
Notes
Pay attention to the writing process of MySQL stored procedures
The difference between stored procedures and functions
The above is the detailed content of How to create a stored procedure in MySQL database?. For more information, please follow other related articles on the PHP Chinese website!