Home > Database > Mysql Tutorial > body text

How to Capitalize the First Letter of Each Word in MySQL?

Susan Sarandon
Release: 2024-11-25 01:35:23
Original
792 people have browsed it

How to Capitalize the First Letter of Each Word in MySQL?

Capitalization Conversion Conundrum in MySQL

When it comes to manipulating strings in MySQL, one common task is capitalizing the first letter of each word. To achieve this, a TSQL equivalent is available in MySQL, but with slight modifications.

Capitalizing the First Letter

The TSQL syntax for capitalizing the first letter is:

UPDATE tb_Company SET CompanyIndustry = UPPER(LEFT(CompanyIndustry, 1)) + SUBSTRING(CompanyIndustry, 2, LEN(CompanyIndustry))
Copy after login

To apply this in MySQL, replace the operator with the CONCAT() function:

UPDATE tb_Company
SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), SUBSTRING(CompanyIndustry, 2))
Copy after login

This effectively achieves the same result as the TSQL equivalent. For example, "hello" becomes "Hello", "wOrLd" becomes "WOrLd", and "BLABLA" remains "BLABLA".

Optional: Capitalizing First Letter and Lowercasing Others

To simultaneously capitalize the first letter and lowercase the remaining characters, use the LCASE function:

UPDATE tb_Company
SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), LCASE(SUBSTRING(CompanyIndustry, 2)))
Copy after login

Note that MySQL uses UCASE and UPPER interchangeably for uppercasing.

The above is the detailed content of How to Capitalize the First Letter of Each Word 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