1. Create a stored procedure
1. Basic Syntax:
Create procedure sp_name ()
Begin
.........
End
2. parameter transfer
Ii. Call the Stored Procedure
1. Basic Syntax: call sp_name ()
Note: The stored procedure name must be enclosed in parentheses, even if the stored procedure has no parameters
Iii. delete stored procedures
1. Basic Syntax:
Drop procedure sp_name //
2. Notes
(1) You cannot delete another stored procedure in one stored procedure. You can only call another stored procedure.
4. blocks, conditions, and loops
1. Block definition, commonly used
Begin
......
End;
You can also create an alias for the block, such:
Lable: begin
...........
End lable;
You can use leave lable to jump out of the block and execute code after the block.
2. conditional statements
IfConditionThen
Statement
Else
Statement
End If;
3. Loop statements
(1). while Loop
[Label:] WHILEExpression DO
Statements
END WHILE [Label];
(2) loop
[Label:]LOOP
Statements
ENDLOOP[Label];
(3). repeat until Loop
[Label:]REPEAT
Statements
UNTIL expression
ENDREPEAT[Label];
5. Other Common commands
1. show procedure status
Displays basic information about all stored procedures in the database, including the database, stored procedure name, and creation time.
2. show create procedure sp_name
Displays detailed information about a stored procedure.