MySQL DELIMITER

While writing the sql statements, we separate statements by semicolon(;). A MySQL program uses the (;) delimiter to separate statements and executes each statement separately.

For example:

SELECT * FROM users;
 
SELECT * FROM messages;

stored procedure, however, consists of multiple statements separated by a semicolon (;).The MySQL program will not treat the whole stored procedure as a single statement, but many statements. Therefore, you must redefine the delimiter temporarily so that you can pass the whole stored procedure to the server as a single statement.

To redefine the default delimiter, use the DELIMITER command:

DELIMITER delimiter_character

The delimiter_character may consist of a single character or multiple characters e.g., // or $$.
 
For example, this statement changes the delimiter to //:

DELIMITER //

Once you change the delimiter, the statements would be

DELIMITER //
 
SELECT * FROM users//
 
SELECT * FROM messages//

Again to change back the delimiter to ; use DELIMITER ; at the end.

Posted on by