【问题标题】:character encoding issue with the BCP and óBCP 和 ó 的字符编码问题
【发布时间】:2015-07-16 22:48:37
【问题描述】:

我有一个文件需要去波兰。在我的数据中,我有一个ó。当我将数据输出到表时,ó 仍然存在,因为字段为NVARCHAR。当我从表格中剪切并粘贴到 Excel 或 Notepad++ 中时,ó 会保留

当我使用 BCP 实用程序导出数据时,如果我在 Excel 或 Notepad++ 中打开生成的文本文件,ó 将更改为 ¢。如果我更改编码,有时字符会变成˘

我尝试了以下命令行开关,一次一个。 -n -N -w

【问题讨论】:

    标签: sql-server unicode character-encoding bcp


    【解决方案1】:

    你看过-C吗?

    -C { ACP | OEM | RAW | code_page }
    
        Specifies the code page of the data in the data file. code_page is
        relevant only if the data contains char, varchar, or text columns
        with character values greater than 127 or less than 32. 
    

    鉴于您的表的数据类型是 Unicode (NVARCHAR),您还必须使用 -c(可能会丢失一些 Unicode 字符)

    -c
        Performs the operation using a character data type. This option
        does not prompt for each field; it uses char as the storage type,
        without prefixes and with \t (tab character) as the field
        separator and \r\n (newline character) as the row terminator. -c
        is not compatible with -w.
    
        For more information, see [Use Character Format to Import or
        Export Data (SQL Server)].
    

    CREATE TABLE [dbo].[Test] (
        [test] [nvarchar](100) NOT NULL
    );  
    
    INSERT [dbo].[Test] ([test]) VALUES (N'helló wórld');
    

    bcp dbo.Test out dbo.Test.dat -c -T -C ACP
    

    -w 没有 -c-C ACP 也应该可以工作,只要 Notepad++ 可以检测到编码(UCS-2 Little Endian)。我使用 Notepad++ 6.7.7 的简单示例没有问题。

    来源:https://msdn.microsoft.com/en-us/library/ms162802.aspx

    【讨论】:

    • 你救了我非常非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多