When I make a stored procedure with SQLYog, it gives me this template:
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `apachelogs`.`test`()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
END$$
DELIMITER ;
I wonder why it changes delimiter before creating stored procedure. And why I can still use ; delimiter inside of create statement(I guess it may because of scope).
That changes the statement delimiter to
$$to keep MySQL from trying to interpret any semicolons inside the stored procedure as a delimiter. Without theDELIMITER $$, you wouldn’t be able to define a stored procedure that contained;to delimit statements inside it. You can think of it as a way to globally escape the semicolon for the duration of the procedure’s definition.From the fine manual:
I don’t know if my explanation is any clearer than the manual’s but maybe one of them (or both combined) will result in some understanding.