Capitalizing the First Letter in MySQL: Equivalent of TSQL
In the realm of database operations, you may encounter situations where you need to capitalize the first letter of specific entries. If you're a seasoned TSQL user, you might be familiar with the syntax to achieve this. However, when working with MySQL, the syntax may differ slightly.
To capitalize the first letter of each entry in a MySQL table, the equivalent of the TSQL code provided is as follows:
UPDATE tb_Company SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), SUBSTRING(CompanyIndustry, 2));
This statement uses the CONCAT() function to concatenate the uppercase version of the first letter (achieved using UCASE() or UPPER()) with the remaining substring of the CompanyIndustry column.
If, however, you want to capitalize only the first letter and convert the remaining letters to lowercase, you can replace UCASE with LCASE:
UPDATE tb_Company SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), LCASE(SUBSTRING(CompanyIndustry, 2)));
It's worth noting that UPPER and UCASE essentially perform the same task of uppercasing strings in MySQL.
The above is the detailed content of How to Capitalize the First Letter in MySQL: Equivalent of TSQL?. For more information, please follow other related articles on the PHP Chinese website!