首字母大写.MySQL

2021-11-20 00:00:00 string mysql capitalize

有人知道 MySQL 中这个 TSQL 的等价物吗?

Does any one know the equivalent to this TSQL in MySQL parlance?

我正在尝试将每个条目的第一个字母大写.

I am trying to capitalize the first letter of each entry.

UPDATE tb_Company SET CompanyIndustry = UPPER(LEFT(CompanyIndustry, 1))
+ SUBSTRING(CompanyIndustry, 2, LEN(CompanyIndustry))

推荐答案

几乎一样,你只需要改用 CONCAT() 函数而不是 + 运算符:

It's almost the same, you just have to change to use the CONCAT() function instead of the + operator :

UPDATE tb_Company
SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), 
                             SUBSTRING(CompanyIndustry, 2));

这会将 hello 变成 HellowOrLd 变成 WOrLdBLABLABLABLA 等.如果你想大写第一个字母,小写另一个,你只需要使用 LCASE 函数:

This would turn hello to Hello, wOrLd to WOrLd, BLABLA to BLABLA, etc. If you want to upper-case the first letter and lower-case the other, you just have to use LCASE function :

UPDATE tb_Company
SET CompanyIndustry = CONCAT(UCASE(LEFT(CompanyIndustry, 1)), 
                             LCASE(SUBSTRING(CompanyIndustry, 2)));

注意 UPPER 和 UCASE 做同样的事情.

Note that UPPER and UCASE do the same thing.

相关文章