In fact, it is to tell the mysql tutorial interpreter whether the command has ended and whether mysql can be executed.
By default, delimiter is a semicolon ;. In the command line client, if a command line ends with a semicolon,
After you press enter, mysql will execute this command. Enter the following statement.
Mysql> select * from test_table;
Press enter, and mysql will immediately execute the statement.
But sometimes, you don't want mysql to do this. The statement contains a semicolon.
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 left (s, n );
Mysql> else
Mysql> if char_length (s) <= n then
Mysql> return s;
Mysql> else
Mysql> return concat (left (s, N-10), '...', right (s, 5 ));
Mysql> end if;
Mysql> end if;
Mysql> end;
By default, it is impossible for the user to execute the entire statement after entering all these statements.
Mysql runs automatically when it encounters a semicolon.
That is, when the statement return '';, the mysql interpreter is executed.
In this case, you need to replace delimiter with another symbol, 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 left (s, n );
Mysql> else
Mysql> if char_length (s) <= n then
Mysql> return s;
Mysql> else
Mysql> return concat (left (s, N-10), '...', right (s, 5 ));
Mysql> end if;
Mysql> end if;
Mysql> end ;//
In this way, the mysql interpreter will execute this statement only when // appears.
Example:
Mysql> delimiter //
Mysql> create procedure simpleproc (out param1 int)
-> Begin
-> Select count (*) into param1 from t;
-> End;
-> //
Query OK, 0 rows affected (0.00 sec)
Mysql> delimiter;
Mysql> call simpleproc (@ );
Query OK, 0 rows affected (0.00 sec)
Mysql> select @;
+ ------ +
| @ A |
+ ------ +
| 3 |
+ ------ +
1 row in set (0.00 sec)