MySQL使用HTML正文列将表连接导出到CSV

时间:2012-10-30 05:35:46

标签: mysql

我有以下查询要导出到CSV,其中包含具有HTML值的列体。

问题是,即使我用空格替换逗号,它也没有正确显示(如没有正确显示),并且行也没有以换行符结束。

SELECT j.id,j.title,j.featured,REPLCAE(j.body,',',' '),j.created,j.created_by,j.start_date,j.end_date,j.apply_link,o.name,o.website,o.logo,o.created,p.code,p.suburb,s.name INTO OUTFILE '/tmp/careersandjobs.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM job j
LEFT JOIN portfolio_job pj
ON pj.job_id = j.id
LEFT JOIN organisation o
ON o.id = j.organisation_id
LEFT JOIN postcode p
ON p.id = j.postcode_id
LEFT JOIN state s
ON s.id = p.state_id
WHERE published = 1
AND end_date > CURDATE()
AND pj.port_id = 8

这背后有原因吗?

@迈克尔

我已尝试过您的建议,但现在会生成此错误:

Failed to execute SQL : SQL SELECT j.id,j.title,j.featured,REPLACE(j.body,',',' ') as body,j.created,j.created_by,j.start_date,j.end_date,j.apply_link,o.name,o.website,o.logo,o.created,p.code,p.suburb,s.name INTO OUTFILE '/tmp/careersandjobs.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY "\n" FROM job j LEFT JOIN portfolio_job pj ON pj.job_id = j.id LEFT JOIN organisation o ON o.id = j.organisation_id LEFT JOIN postcode p ON p.id = j.postcode_id LEFT JOIN state s ON s.id = p.state_id WHERE published = 1 AND end_date > CURDATE() AND pj.port_id = 8 failed : Field separator argument is not what is expected; check the manual

1 个答案:

答案 0 :(得分:0)

你有一些错别字:SELECT j.id,j.title,j.featured,REPLCAE(j.body,',',' '),j.created,j.created_by,j.start_date,j.end_date,j.apply_link,o.name,o.website,o.logo,o.created,p.code,p.suburb,s.name INTO OUTFILE '/tmp/careersandjobs.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n'

你有REPLACE而不是REPLACE