how to find index of the first capital letter in mysql, cyrillic characters -
i have table geographical names of places. have additional letters in front. example if city name astana s.astana
. need name of place astana. want use substr
, can't find index of first capital letter.owh ya cyrillic characters used problem. want give examples:
- Акмолинская область -> Акмолинская
- Кокшетау Г.А. -> Кокшетау
- г.Кокшетау -> Кокшетау
- Красноярский с.о. -> Красноярский
- с.Красный Яр -> Красный Яр
what have tried: created field short_nameru , updated way
update center_kato ck set ck.short_nameru = case when length(substring_index(ck.nameru , ' ', -1)) > length(substring_index(ck.nameru , ' ',1)) substring_index(ck.nameru , ' ', -1) else substring_index(ck.nameru , ' ',1) end
and after updated again
update center_kato ck set ck.short_nameru = case when length(substring_index(ck.short_nameru , '.', -1)) > length(substring_index(ck.short_nameru , '.',1)) substring_index(ck.short_nameru , '.', -1) when length(substring_index(ck.short_nameru , '.', -1)) < length(substring_index(ck.short_nameru , '.',1)) substring_index(ck.short_nameru , '.',1) else ck.short_nameru end
but lost needed values. "зимовка Туяк"
became "зимовка"
needed "Туяк"
i cannot think of way find pattern in string. here brute force approach:
select (case when ascii(substr(cityname, 1, 1)) between ascii('a') , ascii('z') cityname when ascii(substr(cityname, 2, 1)) between ascii('a') , ascii('z') substr(cityname, 2) when ascii(substr(cityname, 3, 1)) between ascii('a' , ascii('z') substr(cityname, 3) when ascii(substr(cityname, 4, 1)) between ascii('a') , ascii('z') substr(cityname, 4) when ascii(substr(cityname, 5, 1)) between ascii('a') , ascii('z') substr(cityname, 5) when ascii(substr(cityname, 6, 1)) between ascii('a') , ascii('z') substr(cityname, 6) when ascii(substr(cityname, 7, 1)) between ascii('a') , ascii('z') substr(cityname, 7) when ascii(substr(cityname, 8, 1)) between ascii('a') , ascii('z') substr(cityname, 8) when ascii(substr(cityname, 9, 1)) between ascii('a') , ascii('z') substr(cityname, 9) when ascii(substr(cityname, 10, 1)) between ascii('a') , ascii('z') substr(cityname, 10) else cityname end)
if know preceding character '.'
, there other approaches.
edit:
the following seems working in cyrillic:
select (case when substr(nameru, 1, 1) between binary 'А' , binary 'Я' nameru when substr(nameru, 2, 1) between binary 'А' , binary 'Я' substr(nameru, 2) when substr(nameru, 3, 1) between binary 'А' , binary 'Я' substr(nameru, 3) when substr(nameru, 4, 1) between binary 'А' , binary 'Я' substr(nameru, 4) when substr(nameru, 5, 1) between binary 'А' , binary 'Я' substr(nameru, 5) when substr(nameru, 6, 1) between binary 'А' , binary 'Я' substr(nameru, 6) when substr(nameru, 7, 1) between binary 'А' , binary 'Я' substr(nameru, 7) when substr(nameru, 8, 1) between binary 'А' , binary 'Я' substr(nameru, 8) when substr(nameru, 9, 1) between binary 'А' , binary 'Я' substr(nameru, 9) when substr(nameru, 10, 1) between binary 'А' , binary 'Я' substr(nameru, 10) else nameru end) mytable;
(for reason, editors rejected edit yernanun, i'm including it.)
Comments
Post a Comment