简体   繁体   中英

mySQL convert a character in a string to upper case

I am relatively new to databases and need a little help with converting characters to uppercase, I can either change the whole string to uppercase or the first letter, however the problem arises when I need to convert a letter that is contained within a string. For example if the surname of an individual in Mcdonald, I need to change this to McDonald or if they have a jnr or snr after their name this needs to be changed to Jnr or Snr. Any guidance would be great.

Thanks

For your requirement, you can use the REPLACE() function. Something like,

UPDATE items SET lastname = REPLACE(lastname, 'MC', 'Mc\' ' );

For "MCDonalds" input, this will return "Mc' Donalds".

http://www.sqlfiddle.com/#!2/6c1da/2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM