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

发布于 2024-09-10 11:33:47 字数 276 浏览 4 评论 0原文

我有以下 sql 语句将 sql 表输出到 csv 文件。

在“内容”列中找到的一些数据包含导致问题的换行符,有没有办法将所有 \n 替换为 's?

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

I have the following sql statement to out put a sql table to a csv file.

Some data found in the column 'content' includes new line charactors which is causing issues, is there a way to replace all \n with 's?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2024-09-17 11:33:47
REPLACE( IFNULL(content , ''), '\n' , '<br/>' ) as content
REPLACE( IFNULL(content , ''), '\n' , '<br/>' ) as content
一场春暖 2024-09-17 11:33:47

尝试:

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) 代表新行。

Try:

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

where CHR(13) represents new line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文