I. Creating a stored Procedure
1. Basic grammar:
CREATE PROCEDURE Sp_name ()
Begin
.........
End
2. Parameter transfer
Two. Call the stored procedure
1. Basic syntax: Call Sp_name ()
Note: The stored procedure name must be followed by parentheses, even if the stored procedure has no parameter passing
Three. Delete stored procedures
1. Basic grammar:
drop procedure sp_name//
2. Matters needing attention
(1) cannot delete another stored procedure in one stored procedure, can only call another stored procedure
Four. blocks, conditions, loops
1. Block definition, commonly used
Begin
......
End
You can also alias a block, such as:
Lable:begin
...........
End lable;
You can use leave lable to jump out of blocks and execute code after blocks
2. Conditional statement
The following are the referenced contents:
If condition Then
Statement
Else
Statement
End If;
3. Circular statements
(1). While loop
The following are the referenced contents:
[Label:] While expression do
Statements
End while [Label];
(2). Loop loop
The following are the referenced contents:
[Label:] LOOP
Statements
End LOOP [Label];
(3). Repeat until cycle
The following are the referenced contents:
[Label:] REPEAT
Statements
UNTIL expression
End REPEAT [Label];
Five. Other common commands
1.show Procedure Status
Displays basic information about stored procedures stored in the database, including the owning database, stored procedure name, creation time, and so on
2.show CREATE PROCEDURE Sp_name
Show details of a stored procedure