DB2 Version 10.1 for Linux, UNIX, and Windows

DIFFERENCE scalar function

Returns a value from 0 to 4 representing the difference between the sounds of two strings based on applying the SOUNDEX function to the strings. A value of 4 is the best possible sound match.

Read syntax diagramSkip visual syntax diagram
>>-DIFFERENCE--(--expression--,--expression--)-----------------><

The schema is SYSFUN.

expression
The arguments can be character strings that are either CHAR or VARCHAR not exceeding 4000 bytes. In a Unicode database, if a supplied argument is a graphic string, it is first converted to a character string before the function is executed. The function interprets data that is passed to it as if it were ASCII characters, even if it is encoded in UTF-8.

The result of the function is INTEGER. The result can be null; if the argument is null, the result is the null value.

Example

The following code:
VALUES (DIFFERENCE('CONSTRAINT','CONSTANT'),SOUNDEX('CONSTRAINT'),
SOUNDEX('CONSTANT')),
(DIFFERENCE('CONSTRAINT','CONTRITE'),SOUNDEX('CONSTRAINT'),
SOUNDEX('CONTRITE'))
returns the following output:
1           2    3
----------- ---- ----
          4 C523 C523
          2 C523 C536

In the first row, the words have the same result from SOUNDEX while in the second row the words have only some similarity.