MySQL - 如何忽略大小写更新和替换数据

3

如何不区分大小写更新列?

如果运行以下查询,它将按预期返回62条记录:

select entity_id 
from field_data_body 
where body_value like '%mailto:iss.servicedesk@example.com%';

返回62条记录

我尝试使用以下查询更新这些记录,将 iss.servicedesk@example.com 替换为 http://iss.servicedesk.example.com

update field_data_body
SET body_value = REPLACE(body_value,'%mailto:iss.servicedesk@example.com%',
                        'http://iss.servicedesk.example.com');

很不幸,由于运行的查询区分大小写,它只更新了52条记录,例如上面的查询中无法识别 Iss.Servicedesk@example.com

我该如何运行上述更新查询,但使其不区分大小写以获取我希望更新的所有表格?

我已更新下面的查询 - 它可以运行,但在我知道需要更新链接的情况下找不到任何结果:

update `field_data_body` SET `body_value` = REPLACE(body_value,'%mailto:iss.servicedesk@example.com%','https://iss.servicedesk.example.com')
where LOWER(CONVERT( body_value USING latin1)) like '%mailto:iss.servicedesk@example.com%'

有没有建议,告诉我应该做些什么来修复它以使其正确运行?
2个回答

4
使用查询时,可以使用UPPER()LOWER()函数。

2

提醒一下:LOWER和UPPER不适用于BINARY、VARBINARY和BLOB类型的字段。如果您的字段属于这些类型之一,则需要使用CONVERT将字符串转换为非二进制字符串:

 LOWER(CONVERT(@str USING latin1))

你能给我一个示例,告诉我如何在我的查询中实现它吗?我对此还有点陌生。 - frodo
其中 LOWER(CONVERT(body_value USING latin1)) like '%mailto:iss.servicedesk@example.com%'; - Diego
我尝试了这个 - 查询运行了,但没有返回任何更新的结果,但我知道有需要更新的表 - 我的语法错了吗:update field_data_body SET body_value = REPLACE(body_value,'%mailto:iss.servicedesk@example.com%','https://iss.servicedesk.example.com') where LOWER(CONVERT( body_value USING latin1)) like '%mailto:iss.servicedesk@example.com%' - frodo
也许 latin1 不是你的排序规则,你知道应该使用哪个吗?或者你可以尝试不使用它来执行查询。 - Diego
utf8 看起来是......我尝试更新 field_data_body SET body_value = REPLACE(body_value,'%mailto:iss.servicedesk@example.com%','https://iss.servicedesk.example.com') where LOWER(CONVERT( body_value USING utf8)) like '%mailto:iss.servicedesk@example.com%',查询像以前一样运行,但没有更新任何记录...在不输入排序类型的情况下运行查询无效... - frodo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接