BULK INSERT fails with row terminator on last row

心已入冬 提交于 2019-12-08 00:11:42

问题


I'm importing a CSV compiled using cygwin shell commands into MS SQL 2014 using:

BULK INSERT import
from 'D:\tail.csv'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\r', FIRSTROW = 1)
GO

I have confirmed that each row contains a \r\n. If I leave a CR/LF on the last row the bulk import fails with Msg 4832:

Bulk load: An unexpected end of file was encountered in the data file.

If I end the file at the end of the last data row then the bulk import succeeds.

For very large CSVs a kludgy way around this problem is to find the number of rows and use the LASTROW setting for the BULK INSERT. Is there a more graceful way to let MS SQL know that, yes, the last row is terminated and not to complain about it or fail on it?


回答1:


Use the following :

BULK INSERT import
from 'D:\tail.csv'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '0x0a', FIRSTROW = 1)
GO


来源:https://stackoverflow.com/questions/25291988/bulk-insert-fails-with-row-terminator-on-last-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!