AppDividend
Latest Code Tutorials

SQL SOUNDEX Function Example Tutorial

0

SQL SOUNDEX is an inbuilt function that accepts the string and returns the phonetic expression, i.e., converts it into four-character code based on how the string sounds when spoken.  The SOUNDEX() function returns the four-character code to evaluate the similarity of two expressions.

SQL SOUNDEX Function

SQL SOUNDEX() converts the string to the four-character code based on how the string sounds when spoken.

See the following syntax.

SELECT SOUNDEX (String);

Parameters

String: The string whose character code has to be retrieved.

Note

  1. The SOUNDEX function returned value will always begin with the first letter of String.
  2. The SOUNDEX function uses only the first five consonants to determine the NUMERIC portion of the value returned, except if the first letter of String is a vowel.
  3. The SOUNDEX function is not case-sensitive, i.e. both uppercase, and lowercase characters will generate the same SOUNDEX function return value.

The first character of the SOUNDEX code is always the first character of an input string.

The second to fourth characters of the code are the numbers that represent the letter in an input string.

The letters A, E, I, O, U, H, W, and Y are ignored if they are not the first letters of a string.

SQL SOUNDEX() function will add zeros at the end of the result code if necessary to make the four-character code.

The primary purpose of the SOUNDEX() function is to compare the similarity between strings in terms of their sounds.

We can check the similarity between SOUNDEX codes of two strings, you use the DIFFERENCE() function.

Example

SELECT SOUNDEX('AppDividend');

Output

A131353

Query 2

SELECT SOUNDEX ('APP DIVIDEND');

Output

A131353

Query 3

SELECT SOUNDEX ('SQL');

Output

S400

Query 4

SELECT SOUNDEX ('SQL IS EASY')

Output

S420

Query 5

SELECT SOUNDEX ('PEACE') AS PEACE, SOUNDEX ('PIECE') AS PIECE;

Output

PEACEPIECE
P200P200

 

Both the strings sound the same, so their Soundex values are the same.

Query 6

SELECT SOUNDEX ('I') AS I, SOUNDEX ('EYE') AS EYE;

Output

IEYE
I000E000

 

Both the strings sound the same but having different Soundex values because they are from different character families.

Let’s apply the Soundex function in a Table.

Table: Employee

Emp_idEmp_nameCityStateSalary
101RohitPatnaBihar30000
201RoheetJalandharPunjab20000
301KaranAllahabadUttar Pradesh40000
401SurajKolkataWest Bengal60000
501SoorajVizagAndhra Pradesh70000

 

Let’s apply the Soundex function on Emp_name to check different Soundex values.

Query

Select Emp_name, SOUNDEX (Emp_name) AS SOUNDEX_VALUE 
from Employee;

Output

Emp_nameSOUNDEX_VALUE
RohitR300
RoheetR300
KaranK650
SurajS620
SoorajS620

 

Here, you can see that Soundex values of Emp_name are displayed having some common values whose names sound the same.

Finally, SQL SOUNDEX Function Example is over.

Related Posts

SQL Right Function

SQL STR Function

SQL Space Function

SQL Rtrim Function

SQL Reverse Function

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.