Maria DB更新并更换

时间:2015-07-23 12:33:51

标签: mysql mariadb

运行时我收到错误消息:

UPDATE catalog_product_entity_text
SET value = REPLACE (value, 'xxxxx') 
WHERE value LIKE 'yyyyy'; 

错误:#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 ')' at line 1

任何想法?

由于

3 个答案:

答案 0 :(得分:3)

我用表达式获得了同样的错误:

UPDATE catalog_product_entity_tex
     SET value = REPLACE (value, 'yyyyy', 'xxxxx')
     WHERE value LIKE '%yyyyy%';

解决方案是使用别名:

UPDATE catalog_product_entity_tex c
     SET c.value = REPLACE (c.value, 'yyyyy', 'xxxxx')
     WHERE c.value LIKE '%yyyyy%';

答案 1 :(得分:0)

replace错了。这是正确的方法:

MariaDB [maison]> select replace('aaaaaa', 'a', 'b');
+-----------------------------+
| replace('aaaaaa', 'a', 'b') |
+-----------------------------+
| bbbbbb                      |
+-----------------------------+
1 row in set (0.01 sec)

您的查询必须是:

UPDATE
   catalog_product_entity_text 
SET 
   value = REPLACE (value, 'xxxxx', 'zzzzz')
WHERE
   value LIKE 'yyyyy';

答案 2 :(得分:0)

替换需要三个参数,而不是两个。大概,你想要:

UPDATE catalog_product_entity_tex
     SET value = REPLACE (value, 'yyyyy', 'xxxxx')
     WHERE value LIKE '%yyyyy%';

另请注意LIKE模式中使用通配符。