BCP 和 ó 的字符编码问题

character encoding issue with the BCP and ó

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

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

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

你调查过 -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. 

鉴于您的 table 的数据类型是 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
没有 -c-C ACP

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

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