Home > Database > Mysql Tutorial > How to create a stored procedure in MySQL database?

How to create a stored procedure in MySQL database?

黄舟
Release: 2017-08-04 13:18:02
Original
6702 people have browsed it

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:

How to create a stored procedure in MySQL database?

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)
);
Copy after login

As shown below:

How to create a stored procedure in MySQL database?

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:

How to create a stored procedure in MySQL database?

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:

How to create a stored procedure in MySQL database?

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:

How to create a stored procedure in MySQL database?

5. The fifth step is to call the stored procedure query_count(), as shown in the figure below:

How to create a stored procedure in MySQL database?

6. Step six, after creating the stored procedure, after calling it, query the results, as shown in the following figure:

How to create a stored procedure in MySQL database?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template