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)
以下是查询以拆分字符串“LearnWithEase”并返回最后一个单词的查询-
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)
热门推荐
9 破五的祝福语简短
10 花童结婚祝福语大全简短
11 客户新房祝福语简短大气
12 小学同学简短祝福语
13 孩子满月红包祝福语简短
14 市场经理生日祝福语简短
15 生女儿送花祝福语简短
16 广场周年庆祝福语 简短
17 书法朋友祝福语简短精辟
18 牛年大气简短的祝福语