让我们首先创建一个表-
mysql> create table DemoTable2017 -> ( -> Name text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2017 values('JOHN SMITH,MYSQL'); mysql> insert into DemoTable2017 values('DAVID MILLER,MONGODB'); mysql> insert into DemoTable2017 values('CHRIS BROWN,JAVA');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable2017;
这将产生以下输出-
+----------------------+ | Name | +----------------------+ | JOHN SMITH,MYSQL | | DAVID MILLER,MONGODB | | CHRIS BROWN,JAVA | +----------------------+ 3 rows in set (0.00 sec)
这是只将首字母设置为大写而其余为小写的查询-
mysql> update DemoTable2017 -> set Name=REPLACE(CONCAT(UPPER(LEFT(Name, 1)), LOWER(SUBSTRING(Name, 2))),' , ', ', '); Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable2017;
这将产生以下输出-
+----------------------+ | Name | +----------------------+ | John smith,mysql | | David miller,mongodb | | Chris brown,java | +----------------------+ 3 rows in set (0.00 sec)