MySQL 查询从分隔符后返回子串?
使用 SUBSTRING() 返回分隔符后的值。我们首先创建一个表 -
mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.56 sec)
使用 insert 命令向表中插入一些记录 -
mysql> insert into DemoTable values('John is good in MySQL,Sam is good in MongoDB,Mike is good in Java'); Query OK, 1 row affected (0.19 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
输出
这将产生以下输出 -
+-------------------------------------------------------------------+ | Title | +-------------------------------------------------------------------+ | John is good in MySQL,Sam is good in MongoDB,Mike is good in Java | +-------------------------------------------------------------------+ 1 row in set (0.00 sec)
以下是返回分隔符后子串的查询。
mysql> select substring(Title, instr(Title, ',') + 1) as AfterDelimiter from DemoTable;
输出
这将产生以下输出 -
+---------------------------------------------+ | AfterDelimiter | +---------------------------------------------+ | Sam is good in MongoDB,Mike is good in Java | +---------------------------------------------+ 1 row in set (0.03 sec)
广告