bcp sqlcmd bulkinsert在unicode问题,Unexpected EOF encountered in BCP data-file

2022-01-11 16:50:13 浏览数 (1)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

senario

进入sqlcmd使用:out xxx产生的数据文件,因为sqlcmd export to file 默认情况下,中国的乱码。因此,使用-u(unicode)开关

代码语言:javascript复制
@echo off & setLocal EnableDelayedExpansion
:start
@SET DB=AdventureWorks2012
sqlcmd  -d�% -b -iscript.sql -v pa="out.txt" pwd="�%" -W -h-1
TIMEOUT 3
sqlcmd  -d�% -b -iout.txt -W -h-1 -s^| -u--<strong><strong>因为sqlcmd export to file 默认情况下中文乱码。故用-u(unicode)开关</strong></strong>
pause
GOTO start

到此,中文正常显示

SQLCMD ERROR

代码语言:javascript复制
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]Unexpected EOF encountered in BCP data-file

0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1

原因 datafile in Unicode format 用-c开关导入数据会出错

查看

打开-w开关,导入成功

小结

用bcp in or out data时

  1. ANSI –> -c
  2. UNICODE–>-w

Using BULK INSERT to Bulk Import Unicode Character Data

代码语言:javascript复制
USE AdventureWorks2012;
GO
BULK INSERT myTestUniCharData 
   FROM 'C:myTestUniCharData-w.Dat' 
   WITH (
      DATAFILETYPE='widechar', --unicoode
      FIELDTERMINATOR=','
   ); 
GO
SELECT Col1,Col2,Col3 FROM myTestUniCharData;
GO

參考:

  • UNICODE与ANSI的差别【转】
  • http://www.cnblogs.com/Pickuper/articles/2050427.html
  • Use Unicode Character Format to Import or Export Data (SQL Server)
  • https://msdn.microsoft.com/en-us/library/ms188289.aspx

版权声明:本文博客原创文章,博客,未经同意,不得转载。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117163.html原文链接:https://javaforall.cn

0 人点赞