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);
这篇关于将现有表格中每个单词的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将现有表格中每个单词的首字母大写
基础教程推荐
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
