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);
这篇关于将现有表格中每个单词的首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将现有表格中每个单词的首字母大写
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 无法解决整理冲突 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
