The method for creating a MySQL stored procedure is relatively basic knowledge. The following describes how to create a MySQL stored procedure. If you are a newcomer to the MySQL database, take a look.
-- Select database
Mysql> use test;
Database changed
-- Create an example table
Mysql> create table zzm (
-> Id int primary key auto_increment,
-> Name varchar (10)
-> );
Query OK, 0 rows affected (0.20 sec)
Mysql> insert into zzm (name) values ('zhang ');
Query OK, 1 row affected (0.08 sec)
Mysql> insert into zzm (name) values ('zeng ');
Query OK, 1 row affected (0.05 sec)
Mysql> insert into zzm (name) values ('ming ');
Query OK, 1 row affected (0.05 sec)
Mysql> select * from zzm;
+ ---- + ------- +
| Id | name |
+ ---- + ------- +
| 1 | zhang |
| 2 | zeng |
| 3 | ming |
+ ---- + ------- +
3 rows in set (0.00 sec)
-- Change the command Terminator because the default command Terminator -- semicolon (;) is often used in procedure (;)
-- Therefore, when creating a procedure, you need to define a new terminator to indicate that the command for creating a procedure ends)
-- Change the end symbol to the dollar sign -- $
Mysql> delimiter $
-- Create MySQL Stored Procedure p3
-- The MySQL stored procedure is named p3, which contains two parameters,
-- One is IN for the input type). The parameter name is nameid and the type is int,
-- One is the output type marked with OUT), the parameter name is person_name, And the type is varchar (10)
-- This stored procedure is used to query all the contents of the zzm table and output the result set data set). Then
-- Query the field name whose ID is recorded in the table and output it to the second output type parameter.
-- No result set is output.
Mysql> create procedure p3 (IN nameid int, OUT person_name varchar (10 ))
-> Begin
-> Select * from test. zzm;
-> Select zzm. name into person_name from test. zzm where zzm. id = nameid;
-> End
-> $
Query OK, 0 rows affected (0.00 sec)
-- After creation, view all created stored procedures in the database.
Mysql> show procedure status $
Edit recommendations]
Three statuses of mysql triggers
Create MySQL trigger syntax
How to Create a master-slave server for mysql
Mysql Aggregate functions
MySQL string case-sensitive Conversion Function