将现有表格中每个单词的首字母大写

Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
本文介绍了将现有表格中每个单词的首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有表people_table",其中包含一个字段 full_name.

I have an existing table 'people_table', with a field full_name.

许多记录的full_name"字段填充了错误的大小写.例如'fred Jones''fred jones''Fred jones'.

Many records have the 'full_name' field populated with incorrect casing. e.g. 'fred Jones' or 'fred jones' or 'Fred jones'.

我可以通过以下方式找到这些错误的条目:

I can find these errant entries with:

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

如何将找到的每个单词的第一个字母大写?例如'fred Jones' 变成 'Fred Jones'.

How can I capitalize the first letter of each word found? e.g. 'fred jones' becomes 'Fred Jones'.

推荐答案

没有 MySQL 函数可以做到这一点,您必须自己编写.在以下链接中有一个实现:

There's no MySQL function to do that, you have to write your own. In the following link there's an implementation:

http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/

为了使用它,首先需要在数据库中创建函数.例如,您可以使用 MySQL 查询浏览器(右键单击数据库名称并选择创建新函数)来执行此操作.

In order to use it, first you need to create the function in the database. You can do this, for example, using MySQL Query Browser (right-click the database name and select Create new Function).

创建函数后,您可以使用如下查询更新表中的值:

After creating the function, you can update the values in the table with a query like this:

UPDATE users SET name = CAP_FIRST(name);

这篇关于将现有表格中每个单词的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)