科学数字BULK INSERT的格式文件

时间:2015-11-12 03:56:12

标签: sql-server formatting ascii

以下ascii文件,带有科学记数法的数字:

   3.1182156e+01       1.2141212e+02       5.6468558e-01    
   3.1182060e+01       1.2141212e+02       5.4650307e-01    
   3.1181965e+01       1.2141212e+02       5.3390592e-01    
   3.1181870e+01       1.2141212e+02       5.2496111e-01    
   3.1181772e+01       1.2141212e+02       5.1364386e-01    
   3.1181677e+01       1.2141212e+02       5.0890839e-01    
   3.1181581e+01       1.2141212e+02       5.0689977e-01

应该是BULK INSERTed到SQL服务器。 [在Notepad ++中,我可以看到每个数字前面有3个空格,并且总是在数字后面有一个标签,如'___ 3.1181581e + 01tab']。实际的ascii文件超过12GB,无法编辑。

目标表是

CREATE TABLE [dbo].[BIG_TEST](
    [lat] [float] NULL,
    [lon] [float] NULL,
    [img1] [float] NULL
) ON [PRIMARY]

BULK INSERT命令是

BULK INSERT BIG_TEST FROM 'C:\test.txt' 
WITH(
FORMATFILE = 'C:\BIG_TEST.xml',
TABLOCK
)

我认为主要问题是格式文件

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <RECORD>
  <FIELD ID =" 1 " xsi:type =" CharTerm " TERMINATOR = " \t" MAXLENGTH = " 16 " />
  <FIELD ID =" 2 " xsi:type =" CharTerm " TERMINATOR = " \t" MAXLENGTH = " 16 " />
  <FIELD ID =" 3 " xsi:type =" CharTerm " TERMINATOR = " \t" MAXLENGTH = " 16 " />
 </RECORD>
 <ROW>
   <COLUMN SOURCE =" 1 " NAME =" lat " xsi:type =" SQLFLT8  "/>
   <COLUMN SOURCE =" 2 " NAME =" lon " xsi:type =" SQLFLT8  "/>
   <COLUMN SOURCE =" 3 " NAME =" img1 " xsi:type =" SQLFLT8  "/>
 </ROW>
</BCPFORMAT>

我根据thisthis Microsoft网站尝试了各种组合,但似乎我无法自己解决这个问题。错误消息是:

Msg 4858, Level 16, State 1, Line 32
Line 4 in format file "C:\BIG_TEST.xml": bad value  CharTerm  for attribute "xsi:type".

非常感谢任何帮助。

0 个答案:

没有答案