mysql& INTO OUTFILE - 转义或替换数据中的新行

时间:2010-07-15 13:06:49

标签: mysql sql csv into-outfile

我有以下sql语句将sql表放到csv文件中。

“内容”一栏中的一些数据包括导致问题的新行字符,有没有办法用's替换所有\ n?

SELECT id, title, content 
INTO OUTFILE '/content.csv'
FIELDS TERMINATED BY ',' ESCAPED BY '\\' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM content

2 个答案:

答案 0 :(得分:2)

REPLACE( IFNULL(content , ''), '\n' , '<br/>' ) as content

答案 1 :(得分:2)

尝试:

SELECT id, title, REPLACE(content , CHR(13), ' ') as content
INTO OUTFILE '/content.csv'
FIELDS TERMINATED BY ',' ESCAPED BY '\\' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM content

其中CHR(13)代表新行。