Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 包]。
Original file line number Diff line number Diff line change
@@ -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 实现]。
Original file line number Diff line number Diff line change
@@ -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].
Original file line number Diff line number Diff line change
@@ -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].
Loading