将SOUNDEX()
返回一个字符串的soundex。听起来几乎相同的两个弦应该具有相同的soundex弦
要soundex()
在MySQL中查询,可以使用以下语法-
select *from yourTableName where soundex(yourValue)=soundex(yourColumnName);
让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(FirstName,LastName) values('Adam','Smith'); mysql> insert into DemoTable(FirstName,LastName) values('David','Miller'); mysql> insert into DemoTable(FirstName,LastName) values('Carol','Taylor'); mysql> insert into DemoTable(FirstName,LastName) values('Chris','Brown'); mysql> insert into DemoTable(FirstName,LastName) values('John','Smith');
使用select语句显示表中的所有记录
mysql> select *from DemoTable;
这将产生以下输出-
+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1 | Adam | Smith | | 2 | David | Miller | | 3 | Carol | Taylor | | 4 | Chris | Brown | | 5 | John | Smith | +----+-----------+----------+ 5 rows in set (0.00 sec)
以下是soundex()
MySQL中的查询。
mysql> select *from DemoTable where soundex('Smith')=soundex(LastName);
这将产生以下输出-
+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1 | Adam | Smith | | 5 | John | Smith | +----+-----------+----------+ 2 rows in set (0.00 sec)