In fact, tell the MySQL tutorial interpreter, whether the command is over, whether MySQL can be executed.
By default, delimiter is a semicolon;. In a command-line client, if a line of commands ends with a semicolon,
Then, after the carriage return, MySQL will execute the command. If you enter the following statement
Mysql> select * from test_table;
And then enter, then MySQL will execute the statement immediately.
But sometimes, you don't want MySQL to do this. A statement containing a semicolon is included in the statement for which you may enter more.
If you try to enter the following statement in the command line client
Mysql> create function ' shorten ' (s varchar (255), n int)
mysql> returns varchar (255)
Mysql> begin
mysql> if IsNull (s) Then
Mysql> return ";
Mysql> ElseIf N<15 Then
Mysql> return to left (S, N);
Mysql> Else
mysql> if Char_length (s) <=n then
Mysql> return s;
Mysql> Else
Mysql> return concat (S, n-10), ' ... ', right (s, 5));
Mysql> End If;
Mysql> End If;
Mysql> end;
By default, it is not possible to wait until the user has completed all of these statements and then execute the entire paragraph.
Because MySQL once encountered a semicolon, it will automatically execute.
That is, the MySQL interpreter will execute when the statement return ';
In this case, you need to replace delimiter with other symbols, such as//or $$.
Mysql> delimiter//
Mysql> create function ' shorten ' (s varchar (255), n int)
mysql> returns varchar (255)
Mysql> begin
mysql> if IsNull (s) Then
Mysql> return ";
Mysql> ElseIf N<15 Then
Mysql> return to left (S, N);
Mysql> Else
mysql> if Char_length (s) <=n then
Mysql> return s;
Mysql> Else
Mysql> return concat (S, n-10), ' ... ', right (s, 5));
Mysql> End If;
Mysql> End If;
Mysql> end;//
This is the only time the MySQL interpreter executes this statement when//appears.
Example:
Mysql> delimiter//
Mysql> CREATE PROCEDURE Simpleproc (out param1 int)
-> begin
-> Select COUNT (*) into the param1 from T;
-> end;
->//
Query OK, 0 rows Affected (0.00 sec)
Mysql> delimiter;
Mysql> call Simpleproc (@a);
Query OK, 0 rows Affected (0.00 sec)
Mysql> Select @a;
+------+
| @a |
+------+
| 3 |
+------+
1 row in Set (0.00 sec)