关于sql:如何小写整个字符串,保持MYSQL中的第一个大写字母

How to lowercase the whole string keeping the first in uppercase in MYSQL

本问题已经有最佳答案,请猛点这里访问。

我的表列-

enter image description here

我的预期输出将在列中更改-

1
Smith, Allen, Doyle, Dennis, Baker, Waker

这是我试过的,但没用:()-

1
2
3
4
5
UPDATE TABLE `employee`
SET last_name = UCASE(LEFT(lower(last_name), 1))

UPDATE TABLE `employee`
SET last_name = ucase(lower(last_name),1)

也访问了此链接-资源

错误--

1
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE `employee` SET last_name = UCASE(LEFT(lower(last_name), 1))' at line 1

让我知道我做错了什么以及如何解决。


TABLE是保留关键字。它应该用反勾号逃跑。

我认为你的问题不应该是TABLE(我认为这是一个错别字)

1
2
UPDATE employee
SET last_Name = CONCAT(UCASE(LEFT(last_Name, 1)), LCASE(SUBSTRING(last_Name, 2)))
  • sqlfiddle演示


试试这个,可能有用

1
2
update `employee`
set name=concat(left(upper(last_name),1),right(lower(last_name),length(last_name)-1));


如果这里有人也在查找如何在包含这两个名称的say a name列中使用大写名和姓氏,下面是一个可能有用的片段:

1
2
3
4
5
6
7
8
9
 SELECT
    CONCAT(
     UCASE(LEFT(substring_index(name, ' ',1),1)),
     LCASE(SUBSTRING(substring_index(name, ' ',1),2)),
    ' ',
     UCASE(LEFT(substring_index(name, ' ',-1),1)),
     LCASE(SUBSTRING(substring_index(name, ' ',-1),2))
    ) as name
FROM table