Uppercase first letter of a string with MySQL
I just searched for a MySQL clone of the ucfirst(string) PHP function which converts the first letter of a string to a capital, but couldn’t find one.
Just to save you some work – I used this:
UPDATE `table` SET `field` = CONCAT(UPPER(LEFT(`field`, 1)), SUBSTRING(`field`, 2))
and if you want to have all other characters lowercased:
UPDATE `table` SET `field` = CONCAT(UPPER(LEFT(`field`, 1)), LOWER(SUBSTRING(`field`, 2)))
Tags: mysql


21. August 2008 at 16:19
Great query !
Very helpful, thanks !!!
6. January 2009 at 15:37
[...] interesting to see the different implications each post had. For instance, one of the first about uppercasing the first letter of a MySQL result value, has brought 313 visitors to this site (through almost as many search phrases) while the one about [...]
9. March 2009 at 23:16
Very helpful query! I couldn’t get another query like this to work, but this one worked perfectly!
Thanks
17. March 2009 at 12:03
Great!! It worked :)
Thank you so much!!
12. July 2009 at 20:20
Without any experience in database and many questions were uppercase on my list for two years.
Thanks for your help on the Internet.