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

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

Linda Hamilton
Release: 2024-11-13 00:09:02
Original
430 people have browsed it

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

Capitalizing First Letter of Each Word in an Existing Table

Problem:

Many records in the people_table have incorrect casing in the full_name field, such as 'fred Jones' or 'Fred jones'. The goal is to capitalize the first letter of each word without disrupting the existing data.

Solution:

MySQL does not provide a built-in function to capitalize the first letter of each word. However, external functions can be created for this purpose.

One such function, called CAP_FIRST, can be implemented as described in the following resource:
http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/

Implementation:

  1. Create the CAP_FIRST function: Follow the instructions provided in the resource to create the function in your database.
  2. Update the full_name field: Execute the following query to update the full_name field in the people_table:
UPDATE people_table SET full_name = CAP_FIRST(full_name);
Copy after login

This operation will capitalize the first letter of each word in the full_name field, correcting the incorrect casing.

The above is the detailed content of How to Capitalize the First Letter of Each Word in a MySQL Table?. 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