【问题标题】:Using BCP to output file as ANSI as UTF-8 MSSQL 2012使用 BCP 将文件作为 ANSI 输出为 UTF-8 MSSQL 2012
【发布时间】:2018-10-24 03:16:23
【问题描述】:

我有带有国际字符的 MSSQL 2012 Server 数据库表。 有什么方法可以将表格 bcp 到 UTF-8 格式的 csv 文件中?

当我试图将代码页 65001 传递给 bcp 命令时,它会抛出错误:

SQL 2012 does not support UTF-8. This code page (65001) is supported from SQL  2016.

Error = [Microsoft][SQL Server Native Client 11.0]This version of SQL Server Native Client does not support UTF-8 encoding (code page 65001)

【问题讨论】:

    标签: sql-server sql-server-2012 bcp


    【解决方案1】:

    代码页 65001 不支持 SQL Server 2012(仅适用于 SQL Server 2016 及更高版本,SQL Server 2016 (13.x) 之前的重要版本不支持代码页 65001 (UTF-8 编码)。来自https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql)。您可以使用 Unicode 1200 页面,然后手动将文件转换为首选代码页。

    另外我推荐使用我的存储过程usp_bcpTableUnload,它有一些改进:将表列名保存到第一行,进行数据排序和其他不错的功能。

    【讨论】:

      【解决方案2】:

      找到在BCP命令Powershell脚本之后运行的解决方案:

      快跑

      PowerShell -Command "Get-Content .\$FILE.txt | Set-Content -Encoding utf8 $FILE.utf8.txt "
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-19
        • 1970-01-01
        • 2021-08-24
        • 1970-01-01
        • 2010-10-17
        • 2019-02-10
        • 1970-01-01
        相关资源
        最近更新 更多