In phpMyAdmin I press export, a window with a script appears

CREATE DEFINER=`srv53642_r`@`%` FUNCTION `translit_func`(`_txt` VARCHAR(250)) RETURNS text CHARSET utf8 BEGIN DECLARE _f varchar(5); DECLARE _t varchar(15); DECLARE done INT DEFAULT FALSE; DECLARE cur CURSOR FOR SELECT f,t from translit; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; open cur; the_loop: LOOP #get the values of each column into our variables FETCH cur INTO _f,_t; IF done THEN LEAVE the_loop; END IF; set _txt=replace(_txt,_f,_t); END LOOP the_loop; CLOSE cur; return _txt; END 

Running this script does not work!

error - "# 1064 - syntax; your SQL syntax;

  • one
    I'm not sure, but I dare to suggest that delimiter should be installed - splash58
  • added delimiter, another error, but the function was created) - Dmitry Portnov
  • and where is she going to go :) - splash58

1 answer 1

The point is that the body of the stored function contains many expressions, terminated by a semicolon. Therefore, using it at the end of the query will fail - the analyzer will not be able to understand which of the semicolons is the final one. Therefore, when creating stored procedures and functions, the sign of the end of a request is usually changed. In the console, this can be done using the DELIMITER command.

 DELIMITER // CREATE DEFINER=`srv53642_r`@`%` FUNCTION `translit_func`(`_txt` VARCHAR(250)) RETURNS text CHARSET utf8 BEGIN DECLARE _f varchar(5); DECLARE _t varchar(15); DECLARE done INT DEFAULT FALSE; DECLARE cur CURSOR FOR SELECT f,t from translit; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; open cur; the_loop: LOOP #get the values of each column into our variables FETCH cur INTO _f,_t; IF done THEN LEAVE the_loop; END IF; set _txt=replace(_txt,_f,_t); END LOOP the_loop; CLOSE cur; return _txt; END// 

In phpMyAdmin, a special text field "Separator" is provided for this, located just below the text area in which the SQL query is placed.