Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use MySQL5 stored procedure

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report