UTL_MATCH package

1. Purpose

The Oracle-compatible UTL_MATCH package provides string matching and similarity computation. It contains four functions: EDIT_DISTANCE, EDIT_DISTANCE_SIMILARITY, JARO_WINKLER, and JARO_WINKLER_SIMILARITY, with behavior matching Oracle. It can be used for spell checking, fuzzy matching and deduplication of short text such as names or addresses, and external data cleansing.

2. Feature Description

2.1. Functions

Function Return type Description

EDIT_DISTANCE(s1, s2)

INTEGER

Minimum number of edits (each insertion, deletion, or substitution of one character counts as 1) needed to transform s1 into s2

EDIT_DISTANCE_SIMILARITY(s1, s2)

INTEGER

Edit-distance-based similarity score, 0–100. 0 means completely different, 100 means identical

JARO_WINKLER(s1, s2)

BINARY_DOUBLE

Jaro-Winkler similarity, 0–1

JARO_WINKLER_SIMILARITY(s1, s2)

INTEGER

JARO_WINKLER multiplied by 100 and rounded, 0–100

2.2. Syntax

SELECT UTL_MATCH.EDIT_DISTANCE(s1, s2)              FROM dual;
SELECT UTL_MATCH.EDIT_DISTANCE_SIMILARITY(s1, s2)   FROM dual;
SELECT UTL_MATCH.JARO_WINKLER(s1, s2)               FROM dual;
SELECT UTL_MATCH.JARO_WINKLER_SIMILARITY(s1, s2)    FROM dual;

s1 and s2 are the strings to compare (VARCHAR2). In Oracle compatibility mode (ivorysql.compatible_mode = oracle), call them directly.

3. Syntax Examples

EDIT_DISTANCE_SIMILARITY produces an integer score from 0 to 100 based on edit distance:

-- completely different strings, returns 0
SELECT UTL_MATCH.EDIT_DISTANCE_SIMILARITY('123456', '456789') AS similarity FROM dual;

-- one character differs, returns 83
SELECT UTL_MATCH.EDIT_DISTANCE_SIMILARITY('123456', '123956') AS similarity FROM dual;

-- identical strings, returns 100
SELECT UTL_MATCH.EDIT_DISTANCE_SIMILARITY('123456', '123456') AS similarity FROM dual;

JARO_WINKLER_SIMILARITY boosts common prefixes and scores the same inputs higher:

-- completely different strings, returns 0
SELECT UTL_MATCH.JARO_WINKLER_SIMILARITY('123456', '456789') AS similarity FROM dual;

-- one character differs, returns 92
SELECT UTL_MATCH.JARO_WINKLER_SIMILARITY('123456', '123956') AS similarity FROM dual;

-- identical strings, returns 100
SELECT UTL_MATCH.JARO_WINKLER_SIMILARITY('123456', '123456') AS similarity FROM dual;

The following examples compare several pairs of strings:

Call Result

EDIT_DISTANCE('shackleford', 'shackelford')

2

EDIT_DISTANCE_SIMILARITY('shackleford', 'shackelford')

82

JARO_WINKLER('shackleford', 'shackelford')

0.9818

JARO_WINKLER_SIMILARITY('shackleford', 'shackelford')

98

EDIT_DISTANCE('kitten', 'sitting')

3

EDIT_DISTANCE_SIMILARITY('kitten', 'sitting')

57

JARO_WINKLER_SIMILARITY('MARTHA', 'MARHTA')

96

JARO_WINKLER_SIMILARITY('DWAYNE', 'DUANE')

84

JARO_WINKLER_SIMILARITY('DIXON', 'DICKSONX')

81

JARO_WINKLER_SIMILARITY('JELLYFISH', 'SMELLYFISH')

90

SELECT UTL_MATCH.EDIT_DISTANCE('shackleford', 'shackelford') AS edit_distance,
       UTL_MATCH.EDIT_DISTANCE_SIMILARITY('shackleford', 'shackelford') AS similarity,
       ROUND(UTL_MATCH.JARO_WINKLER('shackleford', 'shackelford'), 4) AS jaro_winkler,
       UTL_MATCH.JARO_WINKLER_SIMILARITY('shackleford', 'shackelford') AS jw_similarity
  FROM dual;

4. Matching rules

  • Case-sensitive: EDIT_DISTANCE('abc', 'ABC') returns 3, consistent with Oracle.

  • Spaces are treated as ordinary characters: EDIT_DISTANCE('a b', 'ab') returns 1.

  • Byte-based comparison: strings are compared byte by byte rather than character by character (consistent with Oracle). For example, under UTF-8, EDIT_DISTANCE('中文测试', '中文测A') returns 3 (the final multi-byte character differs from A in all 3 of its UTF-8 bytes: 1 substitution plus 2 deletions), and EDIT_DISTANCE_SIMILARITY('中文测试', '中文测A') returns 75 (the maximum length in the formula is 12 bytes).

  • Length limit: the input length limit is 32767 bytes, the same as Oracle’s VARCHAR2 limit. IvorySQL’s implementation does not go through the PostgreSQL fuzzystrmatch extension, so it is not subject to the 255-byte limit of its levenshtein function.

5. NULL and empty strings

UTL_MATCH handles NULL the way Oracle does: it does not propagate NULL but returns a fixed value per function:

Function Return value when an input is NULL

EDIT_DISTANCE(s1, s2)

-1

EDIT_DISTANCE_SIMILARITY(s1, s2)

0 if exactly one input is NULL; 100 if both are NULL

JARO_WINKLER(s1, s2)

0

JARO_WINKLER_SIMILARITY(s1, s2)

0

In Oracle, an empty string is NULL. IvorySQL enables empty-string-to-NULL conversion by default (ivorysql.enable_emptystring_to_NULL = on), so '' behaves like NULL. With that setting disabled, the algorithmic behavior of empty strings becomes observable: EDIT_DISTANCE('', '') returns 0, and EDIT_DISTANCE_SIMILARITY('', '') returns 100.

6. Implementation notes

For algorithm details and the internal design, see UTL_MATCH implementation design.