gpt4 book ai didi

Mysql错误分隔符: Error at Line Delimiter

转载 作者:行者123 更新时间:2023-11-30 21:56:16 26 4
gpt4 key购买 nike

我正在尝试使用我发现的 mysql 函数,但我似乎遇到了一些错误。这是函数:

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');

我正在使用 Mariadb 5.5

Server version: 5.5.50-MariaDB MariaDB Server

这是我看到的错误:

[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 ;

我尝试了一些建议,例如更改原本是管道的分隔符。将分隔符从 END 旁边移动到我所做的下面,但是,错误似乎在两者中都发生了。

我已经尝试了基本的修改来修复错误,但它仍然出现,虽然删除此部分后我不再收到任何错误,但结果不正确。

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;

任何指针都会很棒。

更新

我测试了几个其他版本,也有同样的问题。我目前正在使用 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

最佳答案

我无法重现问题:

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)

关于Mysql错误分隔符: Error at Line Delimiter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45106319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com