What can delimiter in MySQL do? Many people may have such doubts, the following is to introduce you to the role of delimiter MySQL, for your reference.
After MySQL exports one sql:
- DELIMITER $$
- DROP TRIGGER IF EXISTS ' Updateegopriceondelete ' $$
- CREATE
- TRIGGER ' Updateegopriceondelete ' after the DELETE on ' CustomerInfo '
- For each ROW BEGIN
- DELETE from Egoprice WHERE Customerid=old.customerid;
- end$$
- DELIMITER;
Where delimiter a terminator is "$$" and then finally defined as ";", MySQL's default terminator is ";".
Detailed Explanation:
In fact, tell the MySQL 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.
The above is the role of delimiter in MySQL introduced.