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.
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 ;
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:
source
share