Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the function of delimiter in MySql

Shulou Source: shulou.com Published: 2022-05-31 21:39:53 09月21日 Update

What is the role of delimiter in MySql? aiming at this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

After MYSQL exports a SQL:

DELIMITER $$DROP TRIGGER IF EXISTS `updateegopriceondelete` $$CREATE TRIGGER `updateegopriceondelete`AFTER DELETE ON `customerinfo` FOR EACH ROW BEGIN DELETE FROM egoprice WHERE customerId=OLD.customerId; END$$ DELIMITER

Where DELIMITER defines the Terminator as "$$", and then finally defines it as ";". The default Terminator for MYSQL is ";".

Detailed explanation:

In fact, it is to tell the interpreter whether the command has ended and whether the mysql can be executed.

By default, delimiter is a semicolon;. In the command line client, if a line of commands ends with a semicolon

Then after entering the car, mysql will execute the command. Such as entering the following statement

Mysql > select * from test_table

Then enter, and MySQL will execute the statement immediately.

But sometimes, you don't want MySQL to do that. More statements may be entered, and the statement contains a semicolon.

If you try to enter the following statement in the command line client

Mysql > CREATE FUNCTION `SHORTEN` (S VARCHAR, N INT) mysql > RETURNS varchar (255) mysql > BEGIN mysql > IF ISNULL (S) THEN mysql > RETURN; mysql > ELSEIF N RETURN LEFT (S, N); mysql > ELSE mysql > IF CHAR_LENGTH (S) RETURNS; mysql > ELSE mysql > RETURN CONCAT (LEFT (S, NMu10), RIGHT (S, 5)); mysql > END IF; mysql > END IF Mysql > END

By default, it is not possible to wait until the user has entered all these statements before executing the entire statement.

Because mysql automatically executes when it encounters a semicolon.

That is, when the statement RETURN;, the mysql interpreter is about to execute.

In this case, you need to replace delimiter with other symbols, such as / / or $$.

Mysql > delimiter / / mysql > CREATE FUNCTION `SHORTEN` (S VARCHAR / / mysql) mysql > RETURNS varchar (255) mysql > BEGIN mysql > IF ISNULL (S) THEN mysql > RETURN; mysql > ELSEIF N RETURN LEFT (S, N); mysql > ELSE mysql > IF CHAR_LENGTH (S) RETURNS; mysql > ELSE mysql > RETURN CONCAT (LEFT (S, NMAT 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.

The answer to the question about the role of delimiter in MySql is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Statements commands semicolons interpreters inputs situations interpreters questions functions clients clients more Terminators help answers easy easy one line content only Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft vpn Xiaomi Shulou Tech Info