MySQL查询返回分隔符后的子字符串?
用于SUBSTRING()
在定界符后返回值。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Title text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John is good in MySQL,Sam is good in MongoDB,Mike is good in Java');
使用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)