diff --git a/CN/modules/ROOT/pages/master/compatibility_features_design/utl_match_impl.adoc b/CN/modules/ROOT/pages/master/compatibility_features_design/utl_match_impl.adoc new file mode 100644 index 00000000..020596c5 --- /dev/null +++ b/CN/modules/ROOT/pages/master/compatibility_features_design/utl_match_impl.adoc @@ -0,0 +1,14 @@ +:sectnums: +:sectnumlevels: 5 + += UTL_MATCH 实现 + +== 包入口 + +`contrib/ivorysql_ora/src/builtin_packages/utl_match/utl_match--1.0.sql` 中的 PL/iSQL 封装提供 Oracle 兼容的参数和返回类型,调用 `utl_match.c` 中对应的 C 实现。 + +== 距离和相似度 + +编辑距离函数计算 Levenshtein 距离。相似度形式根据字符串长度将距离转换为分数。Jaro–Winkler 函数在窗口范围内匹配字符,考虑匹配字符的顺序,并根据共同前缀调整分数。包同时提供小数和整数两种得分形式。 + +可运行的示例见 xref:master/oracle_compatibility/compat_utl_match.adoc[UTL_MATCH 包]。 diff --git a/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_match.adoc b/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_match.adoc new file mode 100644 index 00000000..9efbff11 --- /dev/null +++ b/CN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_match.adoc @@ -0,0 +1,33 @@ +:sectnums: +:sectnumlevels: 5 + += UTL_MATCH 包 + +== 选择比较方式 + +请用具有包执行权限的角色连接 Oracle 兼容模式。以下函数都接受两个字符串。 + +[cols="2,3",options="header"] +|=== +| 函数 | 结果 +| `EDIT_DISTANCE` | 插入、删除和替换字符所需的最少操作数。 +| `EDIT_DISTANCE_SIMILARITY` | 基于编辑距离的相似度,范围为 0 到 100。 +| `JARO_WINKLER` | 范围为 0 到 1 的相似度,共同前缀会提高得分。 +| `JARO_WINKLER_SIMILARITY` | 整数形式的 Jaro–Winkler 相似度,范围为 0 到 100。 +|=== + +相似度越高,字符串越接近。需要知道修改次数时,请使用编辑距离。比较姓名时,可以用 Jaro–Winkler 对可能的拼写变体排序。比较区分大小写,如需忽略大小写,请先统一两个输入的大小写。 + +== 比较示例字符串 + +[source,sql] +---- +SELECT utl_match.edit_distance('kitten', 'sitting') AS edits, + utl_match.edit_distance_similarity('cat', 'cat') AS exact_score; +SELECT utl_match.jaro_winkler('MARTHA', 'MARHTA') > 0.9 AS close_match, + utl_match.jaro_winkler_similarity('cat', 'cat') AS exact_score; +---- + +第一条查询返回 3 次编辑和 100 分的完全匹配。第二条查询对相近姓名返回真,对相同字符串返回 100 分。 + +实现细节见 xref:master/compatibility_features_design/utl_match_impl.adoc[UTL_MATCH 实现]。 diff --git a/EN/modules/ROOT/pages/master/compatibility_features_design/utl_match_impl.adoc b/EN/modules/ROOT/pages/master/compatibility_features_design/utl_match_impl.adoc new file mode 100644 index 00000000..ad1bf906 --- /dev/null +++ b/EN/modules/ROOT/pages/master/compatibility_features_design/utl_match_impl.adoc @@ -0,0 +1,14 @@ +:sectnums: +:sectnumlevels: 5 + += UTL_MATCH Implementation + +== Package entry points + +The PL/iSQL wrappers in `contrib/ivorysql_ora/src/builtin_packages/utl_match/utl_match--1.0.sql` expose Oracle-compatible argument and return types. They call the corresponding C implementations in `utl_match.c`. + +== Distance and similarity + +The edit-distance functions compute a Levenshtein distance. The similarity form scales the distance by string length to produce a score. The Jaro–Winkler functions compare matching characters within a window, account for their ordering, and adjust the score for a common prefix. The package exposes both the fractional and integer score forms. + +For runnable comparisons, see xref:master/oracle_compatibility/compat_utl_match.adoc[UTL_MATCH package]. diff --git a/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_match.adoc b/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_match.adoc new file mode 100644 index 00000000..bb8cdc7f --- /dev/null +++ b/EN/modules/ROOT/pages/master/oracle_compatibility/compat_utl_match.adoc @@ -0,0 +1,33 @@ +:sectnums: +:sectnumlevels: 5 + += UTL_MATCH Package + +== Choose a comparison + +Connect in Oracle compatibility mode with a role that can execute the package. The functions take two strings. + +[cols="2,3",options="header"] +|=== +| Function | Result +| `EDIT_DISTANCE` | Minimum number of insertions, deletions and substitutions. +| `EDIT_DISTANCE_SIMILARITY` | Edit-distance score from 0 to 100. +| `JARO_WINKLER` | Similarity score from 0 to 1, with extra weight for a shared prefix. +| `JARO_WINKLER_SIMILARITY` | Jaro–Winkler score on an integer scale from 0 to 100. +|=== + +A larger similarity score means a closer match. Use edit distance when the number of changes matters. When comparing names, Jaro–Winkler can help rank likely spelling variations. The comparison is case-sensitive, so normalize both inputs explicitly when case should be ignored. + +== Compare example strings + +[source,sql] +---- +SELECT utl_match.edit_distance('kitten', 'sitting') AS edits, + utl_match.edit_distance_similarity('cat', 'cat') AS exact_score; +SELECT utl_match.jaro_winkler('MARTHA', 'MARHTA') > 0.9 AS close_match, + utl_match.jaro_winkler_similarity('cat', 'cat') AS exact_score; +---- + +The first query returns 3 edits and an exact-match score of 100. The second returns true for the similar names and 100 for the identical strings. + +See xref:master/compatibility_features_design/utl_match_impl.adoc[UTL_MATCH implementation].