mysql - Odd behavior of UPPER in select -


i trying string manipulated within mysql select , seem have strange behavior upper function.

i trying return first letter of word (delimited spaces) , convert upper case. if use upper on single returned letter blank, while if use upper on whole word before getting first letter first letter.

stripping sql down minimum have come test sql:-

select      'verbatim h',      substring(substring_index(substring_index(concat(' ','verbatim h',' '), ' ', 2), ' ', -1), 1, 1),     upper(substring(substring_index(substring_index(concat(' ','verbatim h',' '), ' ', 2), ' ', -1), 1, 1)),     substring(upper(substring_index(substring_index(concat(' ','verbatim h',' '), ' ', 2), ' ', -1)), 1, 1) 

this taking string 'verbatim h', concatenating spaces @ either end getting string between 1st , 2nd space (so verbatim).

the first column full string, 2nd column first letter of first word, 3rd column first letter converted upper case of first word while 4th column first letter of first word converted upper case.

i think columns 3 , 4 should have same values (the difference being 1 converts 1st word upper case before grabbing first letter, while other grabs 1st letter converts upper case), instead 1 contains letter v expect while other contains blank.

if modify above hex values of resulting characters, blank 1 one character string hex value 00, while v hex value of 56.

any suggestions? missing obvious?

the string becomes binary string. , these can't use lower , upper, stated in mysql reference docu

so how solve?

use convert funcion this:

select      'verbatim h',      substring(substring_index(substring_index(concat(' ','verbatim h',' '), ' ', 2), ' ', -1), 1, 1) c1,     upper(convert((substring(substring_index(substring_index(concat(' ','verbatim h',' '), ' ', 2), ' ', -1), 1, 1)) using latin1)) c1_upper; 

here sqlfiddle


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -