Delimiter problems encountered during the first MySQL storage write process

Source: Internet
Author: User

Reprinted: http://www.phppan.com/2010/05/mysql-delimit/

Delimiter problems encountered during the first MySQL storage write process
I wrote the Oracle stored procedure a long time ago. Yesterday, due to some special reasons, I had to write some stored procedures in MySQL.
First, I wrote a very simple stored procedure, but an error is returned for such a simple procedure. The Code is as follows:

12345
 CREATE PROCEDURE test()BEGIN    SELECT 'Hello Word!';                                                               END

Errors are reported on both phpMyAdmin and the client. It is displayed in phpMyAdmin: #1064-you have an error in your SQL syntax; check the manual that corresponds to your MySQL Server version for the right syntax to use near "at line 3

Apparently, an error occurred after the first semicolon.
Unknown reason, then Google, find the following address: http://www.cnblogs.com/hsqzzzl/archive/2008/02/21/1076646.html
The author of the article said: the separator is a symbol that notifies the mysql client that the input has been completed. ";" Is always used, but not in the stored procedure, because many statements in the Stored Procedure need to use semicolons
The Code is as follows:

123456
DELIMITER ||CREATE PROCEDURE test()BEGIN    SELECT 'Hello Word!';                              END ||DELIMITER ;

If you do not want to use delimiter, enter it in the delimiter text box when executing the command in phpMyAdmin. |

Another in Baidu encyclopedia has instructions: http://baike.baidu.com/view/3068266.htm
The delimit command in MySQL.
This command has nothing to do with stored procedures.
In fact, it is to tell the MySQL interpreter whether the command has ended and whether MySQL can be executed.
That is, the input Terminator is changed.
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.
But sometimes, you don't want MySQL to do this. The statement may contain semicolons.
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.
In this case, you can use delimiter to replace delimiter with other symbols, such as // or $.
In this case, Delimiter is used to encapsulate the entire short statement.
This command is used in defining subprograms, triggering programs, and other musql embedded mini programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.