我需要获得行条目的第一段。我怎么能通过查询来做到这一点
答案 0 :(得分:0)
以下是使用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 |
+-----------------------------+