在导出mysql outfile csv时,如何在单个查询中转义反斜杠和双引号

wwwo4jvm  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(399)
SELECT `col 1`, `col 2`, `col 3`, `col 4`, `col 5`
FROM table_name
INTO OUTFILE '/test.csv'
CHARACTER SET utf8
FIELDS TERMINATED BY ','

可选择由“\”括起,由“\”转义

LINES TERMINATED BY '\n'

我已经做了上面的查询来转义双引号,但是我想转义同一查询中的反斜杠和双引号字符。

hmae6n7t

hmae6n7t1#

可能是因为输入字符存在于任何字段上,而不是因为反斜杠。尝试使用replace函数替换enter字符,可能您认为该列有enter字符。请查看下面的示例查询。

SELECT COLUMN1,COLUMN2,REPLACE(COLUMNNAME , '\n', ' ') as COLUMNNAME,... 
INTO OUTFILE '/test.csv' 
CHARACTER SET utf8  
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '\"' 
ESCAPED BY '\"' 
LINES TERMINATED BY '\n'
FROM tableName

希望有帮助。

相关问题