How to Capitalize the First Letter of a String in MySQL
Capitalizing the first letter of each entry in a table can be a useful data manipulation task. In MySQL, there is a simple method to achieve this using the CONCAT() function.
To capitalize the first letter, use the UCASE() or UPPER() function to convert the first character of the string to uppercase, and then concatenate it with the remaining characters using the CONCAT() function.
For example, to capitalize the first letter of each entry in the CompanyIndustry column of the tb_Company table, run the following query:
UPDATE tb_Company SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), SUBSTRING(CompanyIndustry, 2));
This query will convert each entry in the CompanyIndustry column to have the first letter capitalized, while leaving the rest of the string unchanged. For instance, hello becomes Hello, wOrLd becomes WOrLd, and BLABLA becomes BLABLA.
If desired, you can also use the LCASE() function to lowercase the remaining characters in the string:
UPDATE tb_Company SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), LCASE(SUBSTRING(CompanyIndustry, 2)));
This variation will capitalize the first letter and lowercase the remaining characters, resulting in strings like: Hello world, WOrLd!, and BlAbLa.
The above is the detailed content of How to Capitalize the First Letter of a String in MySQL?. For more information, please follow other related articles on the PHP Chinese website!