mysql - Hey i m new and geting error for a simple leveshtein function -


on running below block in phpmyadmin shows

#1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 5

create function levenshtein( s1 varchar(255), s2 varchar(255) )  returns int  deterministic  begin    declare s1_len , s2_len, i, j, c, c_temp, cost int;    declare s1_char char;    -- max strlen=255    declare cv0, cv1 varbinary(256);    set s1_len = char_length(s1), s2_len = char_length(s2), cv1 = 0x00, j = 1, = 1, c = >0;    if s1 = s2      return 0;    elseif s1_len = 0      return s2_len;    elseif s2_len = 0      return s1_len;    else      while j <= s2_len        set cv1 = concat(cv1, unhex(hex(j))), j = j + 1;      end while;      while <= s1_len        set s1_char = substring(s1, i, 1), c = i, cv0 = unhex(hex(i)), j = 1;        while j <= s2_len          set c = c + 1;          if s1_char = substring(s2, j, 1)             set cost = 0; else set cost = 1;          end if;          set c_temp = conv(hex(substring(cv1, j, 1)), 16, 10) + cost;          if c > c_temp set c = c_temp; end if;            set c_temp = conv(hex(substring(cv1, j+1, 1)), 16, 10) + 1;            if c > c_temp               set c = c_temp;             end if;            set cv0 = concat(cv0, unhex(hex(c))), j = j + 1;        end while;        set cv1 = cv0, = + 1;      end while;    end if;    return c;  end; 

just change delimiter

delimiter $$ create function levenshtein(s1 varchar(255), s2 varchar(255))   returns int deterministic begin     declare s1_len , s2_len, i, j, c, c_temp, cost int;     declare s1_char char;     -- max strlen=255     declare cv0, cv1 varbinary(256);     set s1_len = char_length(s1), s2_len = char_length(s2), cv1 = 0x00, j = 1, = 1, c = 0;     if s1 = s2         return 0;     elseif s1_len = 0         return s2_len;     elseif s2_len = 0         return s1_len;     else         while j <= s2_len             set cv1 = concat(cv1, unhex(hex(j))), j = j + 1;         end while;         while <= s1_len             set s1_char = substring(s1, i, 1), c = i, cv0 = unhex(hex(i)), j = 1;             while j <= s2_len                 set c = c + 1;                 if s1_char = substring(s2, j, 1)                      set cost = 0;                  else                      set cost = 1;                 end if;                 set c_temp = conv(hex(substring(cv1, j, 1)), 16, 10) + cost;                 if c > c_temp                      set c = c_temp;                  end if;                 set c > c_temp = conv(hex(substring(cv1, j+1, 1)), 16, 10) + 1;                 if c  c_temp                    set c = c_temp;                  end if;                 set cv0 = concat(cv0, unhex(hex(c))), j = j + 1;             end while;             set cv1 = cv0, = + 1;         end while;     end if; return c; end $$ delimiter ; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -