从txt文件将所有列作为文本导入数据

agyaoht7  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(360)

假设我有这个文本文件:

Name, Zipcode
Person1 2630
Person2, 2500
Person3, NA

我想以文本形式导入所有内容。所以我创建了一个表:

DROP TABLE IF EXISTS ImportFromText;

CREATE TABLE ImportFromText ([Name] nvarchar(50),
                            Zipcode nvarchar(50));
Go

然后我试试这个:

BULK INSERT ImportFromText
FROM 'C:\Users\david\Desktop\Zipcode.txt'
WITH ( FORMAT='CSV',
      ROWTERMINATOR = '\n'
      );
Go

但我有个错误:

Msg 4879, Level 16, State 1, Line 15
Bulk load failed due to invalid column value in CSV data file C:\Users\david\Desktop\Zipcode.txt in row 2, column 1.
Msg 7399, Level 16, State 1, Line 15
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 15
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
tsm1rwdh

tsm1rwdh1#

唯一的问题是第二行中的分隔符(缺少列分隔符)。
修正后代码运行良好。

相关问题