Set MySQL delimiter inside sql file

I want to set the delimiter inside the sql file (because I cannot rely on users to do this through the terminal).

Is there a mysql statement that will allow me to set the delimiter?

Using

DELIMITER //

gives an error message.

# Categories schema

# --- !Ups


CREATE  TABLE IF NOT EXISTS `category` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `pid` INT NULL DEFAULT 0 ,
  `label` VARCHAR(64) NULL ,
  `active` TINYINT NULL DEFAULT 0,
  PRIMARY KEY (`id`) );

DELIMITER //

CREATE FUNCTION hierarchy_connect_by_parent_eq_prior_id(value INT) RETURNS INT
NOT DETERMINISTIC
READS SQL DATA
BEGIN
        DECLARE _id INT;
        DECLARE _parent INT;
        DECLARE _next INT;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET @id = NULL;

        SET _parent = @id;
        SET _id = -1;

        IF @id IS NULL THEN
                RETURN NULL;
        END IF;

        LOOP
                SELECT  MIN(id)
                INTO    @id
                FROM    category
                WHERE   pid = _parent
                        AND id > _id;
                IF @id IS NOT NULL OR _parent = @start_with THEN
                        SET @level = @level + 1;
                        RETURN @id;
                END IF;
                SET @level := @level - 1;
                SELECT  id, pid
                INTO    _id, _parent
                FROM    category
                WHERE   id = _parent;
        END LOOP;
END//

DELIMITER ;

# --- !Downs

#DROP TABLE category;

We got the following error: you have an error in the SQL syntax; check the manual corresponding to the version of MySQL server for the correct syntax to use next to the DELIMITER / CREATE FUNCTION hierarchy_connect_by_parent_eq_prior_id function (value INT) 'on line 1 [ERROR: 1064, SQLSTATE: 42000] when trying to run this SQL script:

+5
source share
3 answers

You say you use

DELIMITER //

But your script says

DELIMITER #

, , , # ? http://dev.mysql.com/doc/refman/5.1/en/comments.html

DELIMITER, .

(, :).)

0

MySql , ";" "|" , , , ; :

- (, , , , ..)

CREATE FUNCTION hierarchy_connect_by_parent_eq_prior_id ( INT) RETURNS INT

- the function body is here

END |

- other instructions or functions here

0
source

Change the delimiter in the sql file as shown below:

  1. -- # delimeter=/

  2. -- # delimeter=;

0
source