title: MySQL DELIMITER not working
body: <p>I've tried a tutorial from <a href="http://explainextended.com/2009/09/29/adjacency-list-vs-nested-sets-mysql/" rel="nofollow">this site</a>, where a sample table gets inserted along with some testing data in a stored procedure. But unfortunately an error message is thrown, saying there's something wrong with the <code>DELIMITER</code>. The whole script is:</p>
  
  <pre><code>CREATE TABLE filler (
      id INT NOT NULL PRIMARY KEY AUTO_INCREMENT
  ) ENGINE=Memory;
  
  CREATE TABLE t_hierarchy (
      id INT NOT NULL PRIMARY KEY,
      parent INT NOT NULL,
      lft INT NOT NULL,
      rgt INT NOT NULL,
      sets LineString NOT NULL,
      data VARCHAR(100) NOT NULL,
      stuffing VARCHAR(100) NOT NULL
  ) ENGINE=MyISAM;
  
  DELIMITER $$
  
  CREATE PROCEDURE prc_filler(cnt INT)
  BEGIN
      DECLARE _cnt INT;
      SET _cnt = 1;
      WHILE _cnt &lt;= cnt DO
              INSERT
              INTO    filler
              SELECT  _cnt;
              SET _cnt = _cnt + 1;
      END WHILE;
  END;
  
  CREATE PROCEDURE prc_hierarchy(width INT)
  main:BEGIN
      DECLARE last INT;
      DECLARE level INT;
      SET last = 0;
      SET level = 0;
      WHILE width &gt;= 1 DO
              INSERT
              INTO    t_hierarchy
              SELECT  COALESCE(h.id, 0) * 5 + f.id,
                      COALESCE(h.id, 0),
                      COALESCE(h.lft, 0) + 1 + (f.id - 1) * width,
                      COALESCE(h.lft, 0) + f.id * width,
                      LineString(
                      Point(-1, COALESCE(h.lft, 0) + 1 + (f.id - 1) * width),
                      Point(1, COALESCE(h.lft, 0) + f.id * width)
                      ),
                      CONCAT('Value ', COALESCE(h.id, 0) * 5 + f.id),
                      RPAD('', 100, '*')
              FROM    filler f
              LEFT JOIN
                      t_hierarchy h
              ON      h.id &gt;= last;
              SET width = width / 5;
              SET last = last + POWER(5, level);
              SET level = level + 1;
      END WHILE;
  END
  $$
  
  DELIMITER ;
  
  START TRANSACTION;
  CALL prc_filler(5);
  CALL prc_hierarchy(585937);
  COMMIT;
  
  CREATE INDEX ix_hierarchy_parent ON t_hierarchy (parent);
  CREATE INDEX ix_hierarchy_lft ON t_hierarchy (lft);
  CREATE INDEX ix_hierarchy_rgt ON t_hierarchy (rgt);
  CREATE SPATIAL INDEX sx_hierarchy_sets ON t_hierarchy (sets);
  </code></pre>
  
  <p>Executing this on a MySQL 5.0.51a-24+lenny2 server gives me the following error message:</p>
  
  <blockquote>
    <p>[Err] 1310 - End-label $$ without match</p>
  </blockquote>
  
  <p>Does anyone know why this occurs and how to fix it?</p>