Home >Database >Mysql Tutorial >How to Capitalize First Letters in Existing MySQL Table Data?

How to Capitalize First Letters in Existing MySQL Table Data?

DDD
DDDOriginal
2024-11-11 19:06:02575browse

How to Capitalize First Letters in Existing MySQL Table Data?

Capitalizing First Letters in Existing Table Data

Many databases contain tables with fields populated with inconsistent letter casing, making it difficult to analyze or display data accurately. In MySQL, the "people_table" might have a "full_name" field with names like 'fred Jones', 'fred jones', or 'Fred jones'.

To find such entries, use the following query:

SELECT * FROM people_table WHERE full_name REGEXP BINARY '^[a-z]';

While MySQL lacks a built-in function to capitalize first letters, you can implement your own. Visit this link for an implementation: http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/.

To use the function:

  1. Create it in the database (e.g., using MySQL Query Browser).
  2. Update the table values using a query like:
UPDATE users SET name = CAP_FIRST(name);

The above is the detailed content of How to Capitalize First Letters in Existing MySQL Table Data?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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