我使用LIKE
和REGEXP
搜索了一个特殊字符“ñ”,结果如下:
CREATE TABLE IF NOT EXISTS `testCharacter` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`name2` char(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`name3` text COLLATE utf8_unicode_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
INSERT INTO `testCharacter` (`id`, `name`, `name2`, `name3`) VALUES
(1, 'ññ', 'ññ', 'ññ'),
(2, 'ñn', 'ñn', 'ñn'),
(3, 'nn', 'nn', 'nn');
首次测试,LIKE
SELECT * FROM `testCharacter` where name like '%ñ%'
并且所有列(where name2 like '%ñ%', where name3 like '%ñ%'
)的结果相同:
+--+-----+------+------+
|id| name| name2| name3|
+--+-----+------+------+
| 1| 'ññ'| 'ññ'| 'ññ'|
| 2| 'ñn'| 'ñn'| 'ñn'|
| 3| 'nn'| 'nn'| 'nn'|
+--+-----+------+------+
第二次测试,REGEXP
SELECT * FROM `testCharacter` where name REGEXP '(ñ)'
并且所有列(where name2 like '%ñ%', where name3 like '%ñ%'
)的结果相同:
+--+-----+------+------+
|id| name| name2| name3|
+--+-----+------+------+
| 1| 'ññ'| 'ññ'| 'ññ'|
| 2| 'ñn'| 'ñn'| 'ñn'|
+--+-----+------+------+
问题,LIKE
字符特价('ñ'
和'n'
)和REGEXP
之间没有区别吗?
适用于带有重音的字符,例如á, é, í, ó, ú