Beckham _ mysql stored procedure, Beckham _ mysql
Stored ProcedureBrief:
1. What is a stored procedure?
2. Use stored procedures
I. Stored Procedure
Similar to a function, a piece of code is encapsulated. You can call this stored procedure to execute this code. In the encapsulated statement body, you can use control statements such as if/else, case, and while to program SQL statements.
Ii. Use stored procedures
2.1 view existing stored procedures
2.2 create a stored procedure
A. Stored Procedure without Parameters
Delimiter // Create procedure p1 () Begin Select count (*) from goods; End // |
|
Call the Stored Procedure p1 ()
B. Stored Procedures with parameters (parameters are used to save running results)
Delimiter // Create procedure p2 (out a int) Begin Select count (*) into a from goods; End // Delimiter; |
|
Call Stored Procedure p2
(Note: Define variable a to maintain the p2 result of the stored procedure, and then display the value of variable)
C. Stored Procedures with parameters (parameters are used for running)
Delimiter // Create procedure p3 (in a int) Begin Select goods_id, goods_name, shop_price from goods where goods_id =; End // Delimiter; |
|
Call Stored Procedure p3
D. Stored Procedure with if/else
Call
E. Stored Procedure with while
2.3 Delete A Stored Procedure
Summary: differences between stored procedures and functions in mysql
A. Different Names
B. The stored procedure does not return values.
The quieter you become, the more you are able to hear!
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.