我有一张如下表
Name
firstname lastname
FirstName Lastname
firstName Lastname
FirstName lastname
我试图在所有4个案例中将firstname
和lastname
的每个字母大写为Firstname Lastname
。
有关查询的任何建议,而不使用CAP_FIRST函数?我可以使用正则表达式吗?
答案 0 :(得分:5)
这是一个有效的查询:
SELECT
CONCAT(
UPPER(SUBSTRING(Name,1,1)),
LOWER(SUBSTRING(Name,2,Locate(' ', Name)-1)),
UPPER(SUBSTRING(Name,Locate(' ', Name)+1,1)),
LOWER(SUBSTRING(Name,Locate(' ', Name)+2)))
FROM NameTable;
结果如下:
Name
Firstname Lastname
Firstname Lastname
Firstname Lastname
Firstname Lastname
要更新列使用,
UPDATE NameTable
SET NameTable.Name = CONCAT(
UPPER(SUBSTRING(Name,1,1)),
LOWER(SUBSTRING(Name,2,Locate(' ', Name)-1)),
UPPER(SUBSTRING(Name,Locate(' ', Name)+1,1)),
LOWER(SUBSTRING(Name,Locate(' ', Name)+2)));
此致