将 char 列转换为 nvarchar,以便更改表中已有数据的代码页(语言编码)? [英] Convert char columns to nvarchar, in order to change the codepage (language encoding) for data already in the table?

查看:50
本文介绍了将 char 列转换为 nvarchar,以便更改表中已有数据的代码页(语言编码)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从另一个来源导入的表,作为具有 char 数据类型的列,但该字段具有国际字符.我想在我的表中使用 nvarcvhar.我怎样才能做到这一点?

I have a table that was imported from another source as a column with the char datatype, but the field has international characters. I would like to use nvarcvhar in my table. How can I achieve this?

我已经尝试更新列(使用alter table 语句或cast as"),但存储的信息没有得到转换.

I already tried updating the columns (using an alter table statement, or "cast as") but the info stored did not get converted.

谢谢

推荐答案

您的数据目前在 EUC-CN 中,伪装成 CP1252.它没有丢失.

Your data is currently in EUC-CN, masquerading as CP1252. It is not lost.

您有多种方法可用于转换为 Unicode(看在转换 SQL 数据库部分进行概述).对于 SQL Server,您可以 创建扩展存储过程,用于从 EUC-CN 到 Unicode 的转换.这会起作用,但并不容易(在这种情况下,您的数据使用代码页 51936).

You have several approaches available for conversion to Unicode (look at Converting SQL databases section for overview). In case of SQL Server, you can create extended stored procedures for conversion from EUC-CN to Unicode. This will work but it is not exactly easy (in this case use code page 51936 for your data).

幸运的话,根据您的数据中出现的特定字符以及您安装的语言包,您可能能够像这样从代码页 936 进行转换:

With some luck, depending on what particular characters occur in your data, and what language packs you have installed, you might be able to convert as if from code page 936 like this:

ALTER DATABASE mydatabasename COLLATE Chinese_PRC

如果成功,请对要转换的每一列执行相同的操作:

If this succeeds, do the same for every column you are going to convert:

ALTER TABLE mytablename ALTER COLUMN mycolumnname
        varchar(4000) COLLATE Chinese_PRC NOT NULL

然后才将它们转换为 NVARCHAR.

And only then convert them to NVARCHAR.

这篇关于将 char 列转换为 nvarchar,以便更改表中已有数据的代码页(语言编码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆