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
SELECT id,fn_remove_accents(name) name
FROM main_creditperson
WHERE name="Irene Olga López";
| id | name |
| ------ | ---------------- |
| 366354 | Irene Olga Lopez |
2条答案
按热度按时间sgtfey8w1#
您可以尝试创建一个函数来替换普通单词的重音符号。
架构(mysql v5.6)
查询#1
db fiddle视图
函数引用
sshcrbum2#
如果
COLLATION
有什么问题吗..._ci
变体,则在比较时忽略重音符号。也就是说,不需要重音消除代码。