[英]Remove \n and everything afterward in mysql column
I have a mysql table like the example below. 我有一个像下面的示例的mysql表。 Sometimes there is
an extra line
a \\n the column with info afterward that I do not need and I would like to remove it keeping only the first line. 有时,\\ n该列后面有
多余的行
,后面是我不需要的信息,我想删除它,只保留第一行。 How would I remove these \\n's and the data afterward in the column? 以后如何删除这些\\ n和数据?
| column1 |
+------------------+
| name1 |
| useless info |
+------------------+
| name2 |
+------------------+
| name3 |
+------------------+
My goal would be to end up with this: 我的目标是最终做到这一点:
| column1 |
+------------------+
| name1 |
+------------------+
| name2 |
+------------------+
| name3 |
+------------------+
Use SUBSTRING_INDEX() 使用SUBSTRING_INDEX()
update your_table
set column1 = SUBSTRING_INDEX(column1 , '\n', 1)
update
t
set t.col1 =
case
when locate("\n",col1) > 0
then left(col1,locate("\n",col1))
else col1 end
from test t
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.