How to use MySQL5 stored procedure
This article mainly introduces how to use MySQL5 stored procedures, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. Download and install, needless to say (I like the non-installed version, decompression can be used, convenient)
2. Start MySQL 5:
Open a console and go to the bin directory of MySQL
Log in, enter: mysql-h localhost-u root-p
3. Select a database: I use test for the entire database. There are no tables in this library.
4. Create a table:
Mysql > CREATE TABLE pet (name VARCHAR (20), owner VARCHAR (20)
-> species VARCHAR (20), sex CHAR (1), birth DATE, death DATE)
5. Insert a row of data:
Mysql > INSERT INTO pet
-> VALUES ('Puffball','Diane','hamster','f','1999-03-30 recording null)
6. Create a process:
Mysql > delimiter / /-this defines the Terminator as "/ /"
Mysql > CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT (*) INTO param1 FROM t
-> END
-> / /
Query OK, 0 rows affected (0.00 sec)
Okay, a process has been created.
7. Execution process:
Mysql > delimiter;-this defines the Terminator as ";", because the above definition is "/ /", so change it back and keep the habit consistent.
Mysql > CALL simpleproc (@ a)
Query OK, 0 rows affected (0.00 sec)
Mysql > SELECT @ a
+-+
| | @ a |
+-+
| | 3 |
+-+
1 row in set (0.00 sec)
Thank you for reading this article carefully. I hope the article "how to use MySQL5 stored procedures" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!