SQL SOUNDEX Function Example
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);
String: The string whose character code has to be retrieved.
- The SOUNDEX function returned value will always begin with the first letter of String.
- 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.
- 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.
SELECT SOUNDEX ('APP DIVIDEND');
SELECT SOUNDEX ('SQL');
SELECT SOUNDEX ('SQL IS EASY')
SELECT SOUNDEX ('PEACE') AS PEACE, SOUNDEX ('PIECE') AS PIECE;
Both the strings sound the same, so their Soundex values are the same.
SELECT SOUNDEX ('I') AS I, SOUNDEX ('EYE') AS EYE;
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.
Let’s apply the Soundex function on Emp_name to check different Soundex values.
Select Emp_name, SOUNDEX (Emp_name) AS SOUNDEX_VALUE from Employee;
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.