sql-server SQL Server业务连续性计划:字段前后有引号,但某些字段中包含引号

dluptydi  于 2022-10-31  发布在  SQL Server
关注(0)|答案(1)|浏览(131)

"CP1000066268","BX101-1219_2016_205649.jpg","FILE - In this Monday, Dec. 19, 2016 file photo Maine Republican Gov. Paul LePage, right, and House Speaker Sara Gideon, D-Freeport, attend the Electoral College vote at the State House in Augusta, Maine. LePage says he had weight loss surgery and jokes that now "there's 50 less pounds of me to hate." The Republican revealed the bariatric surgery for the first time Wednesday, Jan. 11. He says he underwent the procedure on Sept. 29 and returned to work a day later. (AP Photo/Robert F. Bukaty)","","100","69","650","447","0","","","1","","1","0","live","2017-01-11 16:56:18.000"
上述字段终止符(即-t”"、””-r”"\n””)起作用,并将所有.csv数据字段括在引号中。
然而,数据中的一个字段存储了带有引号的文章。当我将数据导入数据库时,它不能完美地复制,因为解析器将文章中的引号解释为终止字段。有简单的修复方法吗?
我尝试了“字段终止于”、“包含于”和“转义于”的多个选项变体,但似乎无法完美地导入文件。
下面是查询结构,以防您不熟悉它:

LOAD DATA LOCAL INFILE '/home/myinfotel/dump_new/NewsItemImages.csv' INTO TABLE NewsItemImages FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

下面是一个未正确复制到数据库中的示例记录:
"CP1000066268","BX101-1219_2016_205649.jpg","FILE - In this Monday, Dec. 19, 2016 file photo Maine Republican Gov. Paul LePage, right, and House Speaker Sara Gideon, D-Freeport, attend the Electoral College vote at the State House in Augusta, Maine. LePage says he had weight loss surgery and jokes that now "there's 50 less pounds of me to hate." The Republican revealed the bariatric surgery for the first time Wednesday, Jan. 11. He says he underwent the procedure on Sept. 29 and returned to work a day later. (AP Photo/Robert F. Bukaty)","","100","69","650","447","0","","","1","","1","0","live","2017-01-11 16:56:18.000"
任何帮助都是感激不尽的!

mlmc2os5

mlmc2os51#

原来从Sql Server Management Studio导出是解决方案(或者我想在命令行中使用sqlcmd命令也可以达到这个目的)。奇怪。我尝试用bcpExcel(它内置在Get Data函数中)导出到CSV,但都没有用。
最后,我求助于从SSMS登录到数据库,并能够在查询中吐出表,并将“结果保存为”到一个. csv中。现在一切都被完美地解析了。下面是我用来指导我解决这个问题的链接。
https://blog.devart.com/how-to-export-sql-server-data-from-table-to-a-csv-file.html

相关问题