AppDividend
Latest Code Tutorials

SQL SOUNDEX Function Example

0

SQL SOUNDEX function accepts the string and returns a 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() converts the string to the four-character code based on how the string sounds when spoken.

SQL SOUNDEX Function

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

PEACE PIECE
P200 P200

 

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

I EYE
I000 E000

 

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_id Emp_name City State Salary
101 Rohit Patna Bihar 30000
201 Roheet Jalandhar Punjab 20000
301 Karan Allahabad Uttar Pradesh 40000
401 Suraj Kolkata West Bengal 60000
501 Sooraj Vizag Andhra Pradesh 70000

 

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_name SOUNDEX_VALUE
Rohit R300
Roheet R300
Karan K650
Suraj S620
Sooraj S620

 

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.