SOUNDEX

SOUNDEX is a function in SQL that converts an alphanumeric string into a four-character code to find similar-sounding words for English language searches. Its primary use is in assisting in fuzzy searches based on phonetics.

SOUNDEX(str)

  • str: This parameter is the string for which the SOUNDEX value will be calculated. SOUNDEX is a phonetic algorithm for indexing names by sound, as pronounced in English, which is useful in situations where you want to find ‘sound-alike’ names in a database. The SOUNDEX(str) function returns a string 4 characters long, starting with a letter.

Example

SELECT SOUNDEX('MySQL') as Soundex_Code;

Output

+--------------+
| Soundex_Code |
+--------------+
| M240 |
+--------------+

Explanation

In this example, the SOUNDEX() function is used on the string ‘MySQL’. The SOUNDEX() function returns a phonetic representation of ‘MySQL’ as ‘M240’. Thus, this function can be used for phonetic comparisons in MySQL.

SOUNDEX( character_expression )

  • character_expression: This is a string expression, such as a column of characters, containing the word to be evaluated by the SOUNDEX function. The function will return a four-character code to evaluate the similarity of these symbols, with the first character being a letter and the remaining three being numbers. The ‘character_expression’ parameter can be of any type that can be implicitly converted to VARCHAR or CHAR data types.

Example

SELECT SOUNDEX('Smith');

Output

S530

Explanation

The SOUNDEX function returns a phonetic representation of a string - a four-character code that is based on how a string sounds when spoken. In the above example, SOUNDEX converts the name ‘Smith’ to ‘S530’.

SOUNDEX(character)

  • character: This is the string parameter upon which the SOUNDEX function is applied. The SOUNDEX function returns a phonetic representation of the provided string by encoding it into an alphanumeric code, taking into account the sound of the letters in the string more than how they’re spelled. This parameter usually represents a word, phrase, character field, or expression that leads to a character string.

Example

SELECT SOUNDEX('Oracle') FROM dual;

Output

A624

Explanation

The SOUNDEX function in Oracle SQL returns a phonetic representation of a string - a code that identifies words sounding similar. In the example above, ‘Oracle’ is coded as ‘A624’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.