简体   繁体   English

MariaDB在“”附近的语法不正确

[英]MariaDB incorrect syntax near ''

as the title says, I have an error with my syntax somewhere. 如标题所示,我的语法有误。 This is MariaDB 10.1.31. 这是MariaDB 10.1.31。

DROP FUNCTION IF EXISTS NO_UMLAUT;
CREATE FUNCTION NO_UMLAUT(TextString VARCHAR(255)) RETURNS VARCHAR(255)
BEGIN
    SET TextString = REPLACE(TextString, 'ä', 'a');
    SET TextString = REPLACE(TextString, 'ë', 'e');
    SET TextString = REPLACE(TextString, 'ḧ', 'h');
    SET TextString = REPLACE(TextString, 'n̈', 'n');
    SET TextString = REPLACE(TextString, 'ï', 'i');
    SET TextString = REPLACE(TextString, 'ẗ', 't');
    SET TextString = REPLACE(TextString, 'ö', 'o');
    SET TextString = REPLACE(TextString, 'ẅ', 'w');
    SET TextString = REPLACE(TextString, 'ß', 'b');
    SET TextString = REPLACE(TextString, 'ü', 'u');
    SET TextString = REPLACE(TextString, 'ẍ', 'x');
    SET TextString = REPLACE(TextString, 'ÿ', 'y');
    RETURN TextString;
END;

and the error: 和错误:

 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 '' at line 3.

So far I tried a function from the documentation and there also was an error with the syntax. 到目前为止,我尝试了文档中的功能,并且语法也有错误。 I am executing this query in HeidiSQL 9.5.0.5196. 我正在HeidiSQL 9.5.0.5196中执行此查询。

I think you just need DELIMITER statements. 我认为您只需要DELIMITER语句。

The function itself is fine, as shown by this SQL Fiddle (MariaDB and MySQL are the same for this purpose). 该函数本身很好,如此SQL Fiddle所示(为此,MariaDB和MySQL是相同的)。

Try adding: 尝试添加:

 DELIMITER $$

 <your function definition>

 DELIMITER ;

A working solution: 一个可行的解决方案:

DROP FUNCTION IF EXISTS NO_UMLAUT;

DELIMITER //
CREATE FUNCTION NO_UMLAUT(TextString VARCHAR(255)) RETURNS VARCHAR(255)
BEGIN
    SET TextString = REPLACE(TextString, 'ä', 'a');
    SET TextString = REPLACE(TextString, 'ë', 'e');
    SET TextString = REPLACE(TextString, 'ḧ', 'h');
    SET TextString = REPLACE(TextString, 'n̈', 'n');
    SET TextString = REPLACE(TextString, 'ï', 'i');
    SET TextString = REPLACE(TextString, 'ẗ', 't');
    SET TextString = REPLACE(TextString, 'ö', 'o');
    SET TextString = REPLACE(TextString, 'ẅ', 'w');
    SET TextString = REPLACE(TextString, 'ß', 'b');
    SET TextString = REPLACE(TextString, 'ü', 'u');
    SET TextString = REPLACE(TextString, 'ẍ', 'x');
    SET TextString = REPLACE(TextString, 'ÿ', 'y');
    RETURN TextString;
END;
//

PS I would recommend to avoid using functions as it drastically decreases database performance. PS我建议避免使用函数,因为它会大大降低数据库性能。 If your goal is performance then it would be better to perform a denormalisation of your database by creating additional field(s) with values with umlauts already removed. 如果您的目标是性能,那么最好通过创建带有已删除变音符号的值的其他字段来对数据库进行非规范化

It would also be better to remove umlauts in your program instead of using a mysql function as unicode can be very tricky and umlauts can be created using different approaches. 最好是在程序中删除变音符号,而不要使用mysql函数,因为unicode可能非常棘手,并且变音符号可以使用不同的方法来创建。 I hope your are not trusting incoming data from external sources, you are sanitising it carefully and your unicode was already normalised before it was put into the database (if not - do it!). 我希望您不信任来自外部源的传入数据,您正在仔细地对其进行清理,并且您的unicode在放入数据库之前已经进行了规范化(如果不这样做,那就这样做吧!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM