I have some weird problem with MySQL
. I am trying to match two strings, but in one string there is extra characters.
Initial string looks like this 'Ascot '
When I select:
select ascii(substring(name, 1, 1)), ascii(substring(name, 7, 1))
I get 194, 194
. But when I replace:
select replace(name, char(194), '' )
it shows as '?Ascot?'
in phpMyAdmin
and no matching is done. Can someone please help me with this?
Problem column is defined as utf8mb4_unicode_ci
. I am trying to match this with column from another table defined as utf8_general_ci
.
Tried to change utf8_general_ci
to utf8mb4_unicode_ci
but with no results.
When I do substring(name, 2, 5)
then it matches. So the solution should be to replace those characters.
EDIT:
I tried the following function to remove non alphanumeric characters and it seems to work now:
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE v_char VARCHAR(1);
DECLARE v_parseStr VARCHAR(255) DEFAULT ' ';
WHILE (i <= LENGTH(prm_strInput) ) DO
SET v_char = SUBSTR(prm_strInput,i,1);
IF v_char REGEXP '^[A-Za-z0-9 ]+$' THEN #alphanumeric
SET v_parseStr = CONCAT(v_parseStr,v_char);
END IF;
SET i = i + 1;
END WHILE;
RETURN trim(v_parseStr);
END
But this is extremely inefficient...