SOUNDS LIKE是 MySQL 中的一个字符串语句,用于查询相似的发音字符串。如果想查询字符串发音可以使用SOUNDEX函数。
str SOUNDS LIKE str
str:字符串。
判断字符串发音是否相似
mysql> SELECT 'sea' SOUNDS LIKE 'see'; +-------------------------+ | 'sea' SOUNDS LIKE 'see' | +-------------------------+ | 1 | +-------------------------+ mysql> SELECT 'sea' SOUNDS LIKE 'eee'; +-------------------------+ | 'sea' SOUNDS LIKE 'eee' | +-------------------------+ | 0 | +-------------------------+
![]() | 'sea' SOUNDS LIKE 'eee' 等价于 SOUNDEX('sea')=SOUNDEX('see'),效果相同。 |
这是详细信息得内容。
-- ---------------------------- -- Table structure for students -- ---------------------------- DROP TABLE IF EXISTS `students`; CREATE TABLE `students` ( `id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Records of students -- ---------------------------- INSERT INTO `students` VALUES ('1', 'Odin'); INSERT INTO `students` VALUES ('2', '小胡'); INSERT INTO `students` VALUES ('3', 'Jack'); INSERT INTO `students` VALUES ('4', 'BOB'); INSERT INTO `students` VALUES ('5', '星星');
原始数据
mysql> SELECT * from students; +----+--------+ | id | name | +----+--------+ | 1 | Odin | | 2 | 小胡 | | 3 | Jack | | 4 | BOB | | 5 | 星星 | +----+--------+
模糊匹配
比如想搜索栏中搜索某个学生名'jack',即使有一个字打错或者打漏得情况,如“jace”,它仍然可以找到。因为发音相识
mysql> SELECT * from students where name SOUNDS LIKE 'Jace'; +----+------+ | id | name | +----+------+ | 3 | Jack | +----+------+
上述示例中,使用SOUNDS LIKE语句查找所有发音类似于`jace`的用户。
总的来说,SOUNDS LIKE语句是 MySQL 中一个非常有用的语句,常用于模糊匹配。在使用SOUNDS LIKE语句时,需要注意其发音规则和兼容性问题。