How can I use jaro-winkler to find the closest value in a table?

 ̄綄美尐妖づ 提交于 2019-12-02 00:26:48

Do you have a list of words that contain words like "Philadelphia"?

And who did write that function?

Oracle has package utl_match for fuzzy text comparison: http://download.oracle.com/docs/cd/E14072_01/appdev.112/e10577/u_match.htm

Can't you do

select w1.word from words w1 where jaro(w1.word,'Philadelphlaa', 9) >= 0.95

?

This will select 'Philadelphia' if that word is present in table words.

A little dirty but faster (untested!).

Let's assume first three characters are the same and length is also approximately the same.

DECLARE
  CURSOR citynames(cp_start in varchar2, cp_length in number) IS
    SELECT city FROM table_loc_master where statecode = 'PQ'
    and   city like cp_start||'%'
    and   length(city) between cp_length -2 and cp_length +2;
  CURSOR leasecity IS
    SELECT city FROM table_loc where State = 'PQ'
    MINUS
    SELECT to_char(city) city FROM table_loc_master where statecode = 'PQ';
  xProb NUMBER(10,8);
BEGIN
  FOR x_rec IN leasecity
  LOOP
      FOR y_rec IN citynames(substr(x_rec.city,1,3), length(x_rec.city))
      LOOP
            xProb := jwrun(x_rec.city,y_rec.city,length(y_rec.city));
            If xProb > 0.97 Then
               DBMS_OUTPUT.PUT_LINE('Source : ' || x_rec.city || ' Target: ' || y_rec.city );
            End if;
      END LOOP;
  END LOOP;
END;
DECLARE
  CURSOR citynames IS
    SELECT city FROM table_loc_master where statecode = 'PQ';
  CURSOR leasecity IS
    SELECT city FROM table_loc where State = 'PQ'
    MINUS
    SELECT to_char(city) city FROM table_loc_master where statecode = 'PQ';
  xProb NUMBER(10,8);
BEGIN
  FOR x_rec IN leasecity
  LOOP
      FOR y_rec IN citynames
      LOOP
            xProb := jwrun(x_rec.city,y_rec.city,length(y_rec.city));
            If xProb > 0.97 Then
               DBMS_OUTPUT.PUT_LINE('Source : ' || x_rec.city || ' Target: ' || y_rec.city );
            End if;
      END LOOP;
  END LOOP;
END;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!