MYSQL command line is used to learn the basic knowledge in the MYSQL database process. How should I use MYSQL command line to create a stored procedure?
I tried some methods, but the first semicolon mysql thought the statement was over. For example:
- CREATE PROCEDURE p7 (IN b INTEGER(12))
-
- begin
-
- declare a INTEGER(12);
-
- set a=5;
-
- INSERT INTO t VALUES (a);
-
- SELECT s1*a FROM t WHERE b<=s1;
-
- End
-
If this stored procedure is directly created on the command line, an error will be reported after you enter a semicolon in the third row ...... Because MYSQL thinks this statement is over, for MYSQL
- CREATE PROCEDURE p7 (IN b INTEGER(12))
-
- begin
-
- declare a INTEGER(12);
-
It must be an error statement.
Then I read something and added the separator --..........
- DELIMITER //
-
- CREATE PROCEDURE p7 (IN b INTEGER(12))
-
- begin
-
- declare a INTEGER(12);
-
- set a=5;
-
- INSERT INTO t VALUES (a);
-
- SELECT s1*a FROM t WHERE b<=s1;
-
- End
-
- //
-
OK ............ That is to say //...... // Run as a statement between them. Therefore, MYSQL receives the complete statement for creating the stored procedure.
In-depth study on MySQL's data deletion from multiple tables
Simple MySQL large table backup method
Combination of multiple MySQL table result sets
Implementation of MySQL table sharding
MySQL authorization table usage example