我有以下查询:
SELECT * FROM main_creditperson WHERE name="Irene Olga López"
这将退出:
id name
366354 Irene Olga López
是否有一种简单的方法可以在查询中执行 ,以便删除所有重音符号的结果?
id name
366354 Irene Olga Lopez
答案 0 :(得分:1)
您可以尝试创建一个将重音符号替换为普通单词的功能。
模式(MySQL v5.6)
Object
查询#1
CREATE TABLE main_creditperson(id int,name Nvarchar(50));
INSERT INTO main_creditperson VALUES (366354,N'Irene Olga López');
ALTER TABLE main_creditperson
MODIFY name VARCHAR(50) CHARACTER SET utf8mb4
COLLATE utf8mb4_bin;
DROP FUNCTION IF EXISTS fn_remove_accents;
DELIMITER |
CREATE FUNCTION fn_remove_accents( textvalue VARCHAR(10000) ) RETURNS VARCHAR(10000)
BEGIN
SET @textvalue = textvalue;
-- ACCENTS
SET @withaccents = 'ŠšŽžÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝŸÞàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿþƒ';
SET @withoutaccents = 'SsZzAAAAAAACEEEEIIIINOOOOOOUUUUYYBaaaaaaaceeeeiiiinoooooouuuuyybf';
SET @count = LENGTH(@withaccents);
WHILE @count > 0 DO
SET @textvalue = REPLACE(@textvalue, SUBSTRING(@withaccents, @count, 1), SUBSTRING(@withoutaccents, @count, 1));
SET @count = @count - 1;
END WHILE;
SET @special = '!@#$%¨&*()_+=§¹²³£¢¬"`´{[^~}]<,>.:;?/°ºª+*|\\''';
SET @count = LENGTH(@special);
WHILE @count > 0 do
SET @textvalue = REPLACE(@textvalue, SUBSTRING(@special, @count, 1), '');
SET @count = @count - 1;
END WHILE;
RETURN @textvalue;
END
|
DELIMITER ;
答案 1 :(得分:0)
如果COLLATION
是..._ci
的任何变体,则在比较时重音将被忽略。也就是说,不需要重音符号。