目錄
1: 如何計算兩字段中字符串的相似程度?
有時候我們需要對比兩個字段相似程度,Oracle提供一個函數用於使用。
涉及函數(11gR2)
UTL_MATCH 的4個子程序來進行處理(subprogram)
Subprogram | Description |
---|---|
EDIT_DISTANCE | Calculates the number of changes required to transform string-1 into string-2 計算字符串string-1 轉成string-2需要做幾次改變 |
EDIT_DISTANCE_SIMILARITY | Calculates the number of changes required to transform string-1 into string-2, returning a value between 0 (no match) and 100 (perfect match) 計算字符串string-1 轉成string-2需要做改變的次數,剩下的值,0代表沒有一個字符匹配,100代表完全匹配 |
JARO_WINKLER | Calculates the measure of agreement between string-1 and string-2 計算字符串1和字符串2之間的一致程度 |
JARO_WINKLER_SIMILARITY | Calculates the measure of agreement between string-1 and string-2, returning a value between 0 (no match) and 100 (perfect match)計算字符串1和字符串2之間的一致程度,返回0(不匹配)和100(完全匹配)之間的值 |
UTL_MATCH函數簡介
The UTL_MATCH package facilitates matching two records. This is typically used to match names, such as two First Names or two Last Names.
譯文:UTL_MATCH包有助於匹配兩個記錄。 這通常用於匹配名稱,例如兩個名或兩個姓。
Edit Distance 概念
“Edit Distance”也稱爲“ Levenshtein距離”(以俄羅斯科學家Vladimir Levenshtein的名字命名,他於1965年設計了該算法),它是兩個字符串s1和s2之間相似度的量度。 距離是將s1轉換爲s2所需的插入,刪除或替換的數量。
UTL_MATCH.EDIT_DISTANCE((string-1, string-2)
UTL_MATCH.EDIT_DISTANCE_SIMILARITY(string-1, string-2)
Jaro-Winkler 概念
“ Jaro-Winkler算法”是另一種計算兩個字符串之間的編輯距離的方法。 在美國人口普查局開發的此方法是一種字符串比較器量度,可提供兩個字符串之間的部分一致值。 字符串比較器考慮了字符串的長度,部分考慮了字母數字字符串中常見的人爲錯誤。
UTL_MATCH.JARO_WINKLER (string-1, string-2)
UTL_MATCH.JARO_WINKLER_SIMILARITY (string-1, string-2)
應用舉例
UTL_MATCH.EDIT_DISTANCE
英文處理
SELECT LENGTHB ('ilovechina') ori_len,
LENGTHB ('lovechina') comp_len,
UTL_MATCH.EDIT_DISTANCE ('ilovechina', 'lovechina') result
FROM DUAL;
中文處理(支持不好)
SELECT LENGTHB ('我愛中國') ori_len,
LENGTHB ('森林好帥') comp_len,
UTL_MATCH.EDIT_DISTANCE ('我愛中國', '森林好帥') result
FROM DUAL;
UTL_MATCH.EDIT_DISTANCE_SIMILARITY
英文處理
SELECT LENGTHB ('ilovechina') ori_len,
LENGTHB ('lovechina') comp_len,
UTL_MATCH.EDIT_DISTANCE_SIMILARITY ('ilovechina', 'lovechina') result
FROM DUAL;
中文處理(支持不好)
SELECT LENGTHB ('我愛中國') ori_len,
LENGTHB ('森林好帥') comp_len,
UTL_MATCH.EDIT_DISTANCE_SIMILARITY ('我愛中國', '森林好帥') result
FROM DUAL;
UTL_MATCH.JARO_WINKLER
英文處理
SELECT LENGTHB ('ilovechina') ori_len,
LENGTHB ('lovechina') comp_len,
UTL_MATCH.JARO_WINKLER ('ilovechina', 'lovechina') result
FROM DUAL;
中文處理(支持不好)
SELECT LENGTHB ('我愛中國') ori_len,
LENGTHB ('森林好帥') comp_len,
UTL_MATCH.JARO_WINKLER ('我愛中國', '森林好帥') result
FROM DUAL;
UTL_MATCH.JARO_WINKLER_SIMILARITY
英文處理
SELECT LENGTHB ('ilovechina') ori_len,
LENGTHB ('lovechina') comp_len,
UTL_MATCH.JARO_WINKLER_SIMILARITY ('ilovechina', 'lovechina') result
FROM DUAL;
中文處理(支持不好)
SELECT LENGTHB ('我愛中國') ori_len,
LENGTHB ('森林好帥') comp_len,
UTL_MATCH.JARO_WINKLER_SIMILARITY ('我愛中國', '森林好帥') result
FROM DUAL;