APEX Oracle 比较两个字段 (varchar2)
APEX Oracle Compare Two Fields (varchar2 )
我想比较两个 varchar2 字段,并根据相似度百分比在我的函数中得到这个百分比,以及这个记录的 ID table。
我有table(SYMPTOMS
),我还有这个table的字段Symptom_Descr
(VARCHAR2)和变量v_symptom
( varchar2),我想将此变量与此字段进行比较。
例如,这是我的 table:
我要比较的变量是:
'flashes the room lights 5 times'
我要结果=
id
1
0%
2
0%
3
90%
另一个例子如果变量是'washes her hands 7 times'
:
id
1
80%
2
0%
3
10%
以上百分比不准确。
如果以上都做不到,那我该怎么做才能找到相似之处呢?
您可以使用 UTL_MATCH
包:
SELECT id,
UTL_MATCH.EDIT_DISTANCE_SIMILARITY(
symptom_descr,
'flashes the room lights 5 times'
) AS ed_similarity,
UTL_MATCH.JARO_WINKLER_SIMILARITY(
symptom_descr,
'flashes the room lights 5 times'
) AS jw_similarity
FROM symptoms;
其中,对于示例数据:
CREATE TABLE symptoms (id, symptom_descr) AS
SELECT 1, 'washes his hands constantly' FROM DUAL UNION ALL
SELECT 2, 'checks several times if he turned off the water heater' FROM DUAL UNION ALL
SELECT 3, 'flashes the room lights too many times' FROM DUAL;
输出:
ID
ED_SIMILARITY
JW_SIMILARITY
1
30
62
2
25
62
3
79
93
db<>fiddle here
我想比较两个 varchar2 字段,并根据相似度百分比在我的函数中得到这个百分比,以及这个记录的 ID table。
我有table(SYMPTOMS
),我还有这个table的字段Symptom_Descr
(VARCHAR2)和变量v_symptom
( varchar2),我想将此变量与此字段进行比较。
例如,这是我的 table:
我要比较的变量是:
'flashes the room lights 5 times'
我要结果=
id | |
---|---|
1 | 0% |
2 | 0% |
3 | 90% |
另一个例子如果变量是'washes her hands 7 times'
:
id | |
---|---|
1 | 80% |
2 | 0% |
3 | 10% |
以上百分比不准确。
如果以上都做不到,那我该怎么做才能找到相似之处呢?
您可以使用 UTL_MATCH
包:
SELECT id,
UTL_MATCH.EDIT_DISTANCE_SIMILARITY(
symptom_descr,
'flashes the room lights 5 times'
) AS ed_similarity,
UTL_MATCH.JARO_WINKLER_SIMILARITY(
symptom_descr,
'flashes the room lights 5 times'
) AS jw_similarity
FROM symptoms;
其中,对于示例数据:
CREATE TABLE symptoms (id, symptom_descr) AS
SELECT 1, 'washes his hands constantly' FROM DUAL UNION ALL
SELECT 2, 'checks several times if he turned off the water heater' FROM DUAL UNION ALL
SELECT 3, 'flashes the room lights too many times' FROM DUAL;
输出:
ID ED_SIMILARITY JW_SIMILARITY 1 30 62 2 25 62 3 79 93
db<>fiddle here