Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of delimiter in MySql

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report