mySQL UCFIRST Capitalize the first letter of each word using MYSQL
for mySQL UCFIRST we need to do the following steps
1. Divide the string into two segments using mysql function SUBSTRING.
2. First part will be the single letter which we will converting that to upper case using mysql function UCASE. To acheive this we will use UCASE(SUBSTRING(‘column_name’, 1,1)).
3. Second part will be the remaining letters. We will convert these letter to lower case mysql function LOWER. To acheive this we will use LOWER(SUBSTRING(‘column_name’, 2)).
4. Then we will contact both the parts using mysql function CONCAT.
mysql ucfirst example query:
UPDATE ‘table’ SET source_field = CONCAT(UCASE(SUBSTRING(‘column_name’, 1,
1)),LOWER(SUBSTRING(‘column_name’, 2)))
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Thanks for this, saved me a ton of time. However in your text above, your source backquotes are coming out as some strange left and right quotes that mysql doesn’t understand. Maybe this one will print out correctly on this page:
UPDATE `source` SET `field` = CONCAT(UCASE(SUBSTRING(`field`, 1,
1)),LOWER(SUBSTRING(`field`, 2)))
Thanks again for the good tip!