MySQL查询将字符串“ Learn With Ease”拆分并返回最后一个单词?
为此,您可以使用SUBSTRING_INDEX()。让我们首先创建一个表-
mysql> create table DemoTable(
Words TEXT
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Learn With Ease');mysql> insert into DemoTable values('Intro To MySQL');
mysql> insert into DemoTable values('Deep Dive Using Java');
mysql> insert into DemoTable values('C++ In Depth');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------------------+| Words |
+-----------------------+
| Learn With Ease |
| Intro To MySQL |
| Deep Dive Using Java |
| C++ In Depth |
+-----------------------+
4 rows in set (0.00 sec)
以下是查询以拆分字符串“ Learn With Ease”并返回最后一个单词的查询-
mysql> update DemoTable set Words=substring_index(Words,' ',-1);Rows matched : 4 Changed : 4 Warnings : 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+| Words |
+----------+
| Ease |
| MySQL |
| Java |
| Depth |
+----------+
4 rows in set (0.00 sec)
以上是 MySQL查询将字符串“ Learn With Ease”拆分并返回最后一个单词? 的全部内容, 来源链接: utcz.com/z/335222.html