Home > Database > Mysql Tutorial > How to Capitalize the First Letter of a String in MySQL?

How to Capitalize the First Letter of a String in MySQL?

Susan Sarandon
Release: 2024-11-22 07:33:15
Original
880 people have browsed it

How to Capitalize the First Letter of a String in MySQL?

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));
Copy after login

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)));
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template