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:

 
 
 

2 Responses to “Uppercase first letter of a string with MySQL”

  1. Gravatar of Alexey Alexey
    21. August 2008 at 16:19

    Great query !
    Very helpful, thanks !!!

  2. Gravatar of » Blog traffic in 2008 - internet development - strictlyPHP » Blog traffic in 2008 - internet development - strictlyPHP
    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 [...]

Leave a Reply