1

我用来freebcp将数据批量复制到 SQL Server。它工作正常,除了最终被截断为整数的数值。数据库中的列是 a FLOAT,因此它可以处理带小数的值。

命令

freebcp MyDatabase.MySchema.MyTable in /path/to/myfile.txt -c -S MyServer -U MyUser -P MyPassword

MyTable 有 5 列,第一列是 2 INTEGER,其他是 FLOAT。

样品来自myfile.txt

19344   303634  -0.419398400743657  -1.38936409312037   0.550567291633061
19345   303634  -1.59787440264054   -2.05068741446749   -1.14506139081359

存储为

19344   303634  0   -1  1
19345   303634  -2  -2  -1

如何解决这个问题?

注意:我freebcp在 Ubuntu 下使用。在 Windows 下使用时bcp,浮动列可以正确导出,同时使用几乎相同的语法(只需替换freebcpbcp使用推力连接)。

bcp MyDatabase.MySchema.MyTable in /path/to/myfile.txt -c -S MyServer -T
4

1 回答 1

0

Questioner originally stated data type of three columns with decimal places was NUMERIC. Questioner edited question, changing data type to FLOAT, in response to this answer.

NUMERIC is functional equivalent to DECIMAL. msdn - NUMERIC

Are the precision and scale defined for the NUMERIC columns in the SQL table? When they are not defined the default precision is 18 and the scale is 0. Therefore if they are not defined you will have 0 places to the right of the decimal place.

If you cannot predict the number of decimal places (scale) you need, then the FLOAT data type is more appropriate. msdn - FLOAT

Otherwise, you need to set the precision and scale for NUMERIC.

于 2016-04-21T13:09:04.653 回答