本文介绍了在MySQL中导出具有换行符的列的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SQL缺乏经验,因此应该有一个简单的解决方案来解决我的问题:我正在将一个表选择到一个用逗号分隔的文件中,并且TEXT类型的列具有换行符,因此,当我尝试将csv导入Excel时,它将在换行符之后的每段文本中创建单独的行.

I am pretty inexperienced in SQL, so there should be a simple solution to my problem:I am selecting a table into a comma-separated file, and the column of type TEXT has newline characters, so when I try to import my csv into Excel, it creates separate rows each piece of text following a newline character.

这是我的查询:

SELECT * FROM `db`.`table` INTO OUTFILE 'c:\\result.txt' FIELDS TERMINATED BY ','
ESCAPED BY '\\' OPTIONALLY ENCLOSED BY '"'  LINES TERMINATED BY '\r\n' ;

然后在Excel中,我导入为逗号分隔的文件,这会导致带有换行符的文本列出现问题.

and then in Excel I import as a comma separated file which causes issues for column that has text with newline characters.

感谢您的帮助!

推荐答案

也许只需将所有内容都用双引号引起来即可.

Just enclose everything in double quotes perhaps.

SELECT * FROM db.table INTO OUTFILE 'c:/result.txt'  FIELDS TERMINATED BY ',' ESCAPED BY '\\' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';

这篇关于在MySQL中导出具有换行符的列的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 20:41