-3
我需要获取一行记录的第一段。我怎样才能通过查询来做到这一点MySQL获取两段落标签之间的文本子串
我需要获取一行记录的第一段。我怎样才能通过查询来做到这一点MySQL获取两段落标签之间的文本子串
这是一个演示,使用SUBSTRING_INDEX()函数返回文本块的第一段,假定段落由换行符分隔。
mysql> create table t (t text);
mysql> insert into t (t) values ('now is the time\nfor all good men');
mysql> select * from t;
+----------------------------------+
| t |
+----------------------------------+
| now is the time
for all good men |
+----------------------------------+
mysql> select substring_index(t, '\n', 1) from t;
+-----------------------------+
| substring_index(t, '\n', 1) |
+-----------------------------+
| now is the time |
+-----------------------------+