【问题标题】:APEX Oracle Compare Two Fields (varchar2 )APEX Oracle 比较两个字段 (varchar2)
【发布时间】:2021-12-24 17:59:36
【问题描述】:

我想比较两个 varchar2 字段并根据相似度百分比来在我的函数中获取此百分比,以及此表中此记录的 ID。

我有表 (SYMPTOMS),我还有这个表的字段 Symptom_Descr (VARCHAR2) 和变量 v_symptom (varchar2),我想将此变量与此字段进行比较。

例如,这是我的桌子:

我要比较的变量是: '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%

上述百分比并不准确。

如果以上都做不到,那我该怎么做才能找到相似之处呢?

【问题讨论】:

    标签: sql oracle11g oracle-apex oracle-apex-5.1


    【解决方案1】:

    您可以使用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小提琴here

    【讨论】:

    • 您好@MT0,感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2011-10-30
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多