获取字段值并从 MySQL 中将特定字符转换为大写


我们先创建一个表 -

mysql> create table DemoTable1897
   (
   Name varchar(20)
   );
Query OK, 0 rows affected (0.00 sec)

使用 insert 命令在表中插入一些记录 -

mysql> insert into DemoTable1897 values('john');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('Chris');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('jace');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('Chris');
Query OK, 1 row affected (0.00 sec)

使用 select 语句显示表中的所有记录 -

mysql> select * from DemoTable1897;

这将产生以下输出 -

+-------+
| Name  |
+-------+
| john  |
| Chris |
| jace  |
| David |
| Chris |
+-------+
5 rows in set (0.00 sec)

以下是获取字段值并将特定字符转换为大写的查询

mysql> select replace(Name,'j','J') from DemoTable1897;

这将产生以下输出 -

+-----------------------+
| replace(Name,'j','J') |
+-----------------------+
| John                  |
| Chris                 |
| Jace                  |
| David                 |
| Chris                 |
+-----------------------+
5 rows in set (0.00 sec)

更新于:2019 年 12 月 27 日

99 次浏览

启动您的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.