MariaDB SOUNDEX() Function

In MariaDB, SOUNDEX() is a built-in string function that returns a soundex string representing the pronunciation of a given string.

The SOUNDEX() function is used to compare whether the pronunciation of two words is the same. If two words sound the same, their soundex strings are the same.

MariaDB SOUNDEX() Syntax

Here is the syntax of the MariaDB SOUNDEX() function:

SOUNDEX(string)

Parameters

string

Required. a string.

If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'SOUNDEX'.

Return value

The MariaDB SOUNDEX(string) function returns a soundex string representing the pronunciation of the string.

The standard soundex string has four characters, but the string returned by the SOUNDEX() function may be longer than four. If you want to get the standard soundex string, you can use the SUBSTRING() function to intercept the result of the SOUNDEX() function.

The SOUNDEX(string) function only handles letters in string, non-alphabetic characters are ignored.

MariaDB SOUNDEX() Example

Let’s look at a few SOUNDEX() examples:

SELECT
    SOUNDEX('Hello'),
    SOUNDEX('World');

Output:

+------------------+------------------+
| SOUNDEX('Hello') | SOUNDEX('World') |
+------------------+------------------+
| H400             | W643             |
+------------------+------------------+

Let’s look at a few words with the same soundex:

SELECT
    SOUNDEX('Dam'),
    SOUNDEX('Damn'),
    SOUNDEX('Too'),
    SOUNDEX('Two'),
    SOUNDEX('Color'),
    SOUNDEX('Colour')\G

Output:

   SOUNDEX('Dam'): D500
  SOUNDEX('Damn'): D500
   SOUNDEX('Too'): T000
   SOUNDEX('Two'): T000
 SOUNDEX('Color'): C460
SOUNDEX('Colour'): C460

Although some words sound the same, they have different soundex strings if they start with different letters.

SELECT
    SOUNDEX('Hole'),
    SOUNDEX('Whole'),
    SOUNDEX('Our'),
    SOUNDEX('Hour')\G

Output:

 SOUNDEX('Hole'): H400
SOUNDEX('Whole'): W400
  SOUNDEX('Our'): O600
 SOUNDEX('Hour'): H600

Conclusion

In MariaDB, SOUNDEX() is a built-in string function that returns a soundex string representing the pronunciation of a given string.