[英]Mysql Error Delimiter: Error at Line Delimiter
I am trying to use a mysql function that I have found but I seem to be getting some errors with this. 我正在尝试使用我发现的mysql函数,但似乎与此有关。 Here is the function: 这是函数:
SET GLOBAL log_bin_trust_function_creators=1;
DROP FUNCTION IF EXISTS digits;
DELIMITER $$
CREATE FUNCTION digits( str CHAR(32) ) RETURNS CHAR(32)
BEGIN
DECLARE i, len SMALLINT DEFAULT 1;
DECLARE ret CHAR(32) DEFAULT '';
DECLARE c CHAR(1);
SET len = CHAR_LENGTH( str );
REPEAT
BEGIN
SET c = MID( str, i, 1 );
IF c BETWEEN '0' AND '9' THEN
SET ret=CONCAT(ret,c);
END IF;
SET i = i + 1;
END ;
UNTIL i > len END REPEAT;
RETURN ret;
END
$$
DELIMITER ;
SELECT digits('123ab45cde6789fg');
I am using Mariadb 5.5 我正在使用Mariadb 5.5
Server version: 5.5.50-MariaDB MariaDB Server
Here is the error that I see: 这是我看到的错误:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '$$
DELIMITER ;
I have tried a few suggestions such as changing the delimiter which was originally a pipe. 我尝试了一些建议,例如更改了最初是管道的定界符。 Moving the delimiter from next to END
to underneath it which I have done, however, the error seems to occur in both. 将分隔符从END
旁边移到END
的下面,但是,似乎两者都出现了错误。
I have tried basic modifications to fix the error but it still occurs, it seems though when removing this section I no longer get any errors, but the result is not correct. 我已经尝试了基本的修改来解决该错误,但是仍然会发生,尽管在删除本节时,我似乎不再遇到任何错误,但是结果不正确。
REPEAT
BEGIN
SET c = MID( str, i, 1 );
IF c BETWEEN '0' AND '9' THEN
SET ret=CONCAT(ret,c);
END IF;
SET i = i + 1;
END ;
UNTIL i > len END REPEAT;
Any pointers would be great. 任何指针都很棒。
Update 更新资料
I have tested a few other versions and have the same issue. 我已经测试了其他几个版本,并且存在相同的问题。 I am using Navicat currently. 我目前正在使用Navicat。
Server version: 5.5.50-MariaDB MariaDB Server
Server version: 5.5.31-0ubuntu0.12.10.1 (Ubuntu)
Server version: 5.1.73 Source distribution
Server version: 5.5.52-MariaDB MariaDB Server
I can't reproduce the problem: 我无法重现该问题:
MariaDB [_]> SELECT VERSION();
+----------------+
| VERSION() |
+----------------+
| 5.5.56-MariaDB |
+----------------+
1 row in set (0.00 sec)
MariaDB [_]> SET GLOBAL log_bin_trust_function_creators=1;
Query OK, 0 rows affected (0.00 sec)
MariaDB [_]> DROP FUNCTION IF EXISTS digits;
Query OK, 0 rows affected (0.00 sec)
MariaDB [_]> DELIMITER $$
MariaDB [_]> CREATE FUNCTION digits( str CHAR(32) )
-> RETURNS CHAR(32)
-> BEGIN
-> DECLARE i, len SMALLINT DEFAULT 1;
-> DECLARE ret CHAR(32) DEFAULT '';
-> DECLARE c CHAR(1);
-> SET len = CHAR_LENGTH( str );
-> REPEAT
-> BEGIN
-> SET c = MID( str, i, 1 );
-> IF c BETWEEN '0' AND '9' THEN
-> SET ret=CONCAT(ret,c);
-> END IF;
-> SET i = i + 1;
-> END;
-> UNTIL i > len END REPEAT;
-> RETURN ret;
-> END$$
Query OK, 0 rows affected (0.00 sec)
MariaDB [_]> DELIMITER ;
MariaDB [_]> SELECT digits('123ab45cde6789fg');
+----------------------------+
| digits('123ab45cde6789fg') |
+----------------------------+
| 123456789 |
+----------------------------+
1 row in set (0.00 sec)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.