Oracle中如何转换列的字符集

发布于 2024-10-21 23:10:13 字数 328 浏览 27 评论 0原文

我有一个表,我们的服务提供商在其中插入了 UNICODE 数据,但我的 Oracle 字符集是 WE8ISO8859P1。

现在为了获取数据,我使用了 Oracle 的以下功能,但它显示?????????

select CONVERT(message,'AL32UTF8','WE8ISO8859P1') from client_campaigns

还有一件事消息可以是 CLOB 类型。

由于数据丢失,我无法更改数据库的字符集,其次它在生产中,字符集的更改可能会导致错误。

现在请指导我如何以 UNICODE 形式获取此数据?

问候, 伊姆兰

I have a table in which our service provider insert UNICODE data but my oracle characterset is WE8ISO8859P1.

Now to get that data i used following function of oracle but it is displaying ???????

select CONVERT(message,'AL32UTF8','WE8ISO8859P1') from client_campaigns

one thing more message coulmn is of CLOB type.

I cant change characterset of my Database due to dataloss and second its in production and changes in characterset may lead to errors.

Now please guide how i can get this data as UNICODE?

Regards,
imran

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小忆控 2024-10-28 23:10:13

插入字符(VARCHAR2 或 CHAR 或 CLOB)列中的字符串将始终转换为数据库字符集。这意味着在您的情况下插入的数据将转换为 WE8ISO8859P1。由于 UNICODE 不是 WE8ISO8859P1 的子集,因此您将丢失信息。某些在您的字符集中不可用的字符在插入时会转换为 ?

你应该做什么?对于新数据,有几个选项:

  1. 将列的数据类型修改为 NVARCHAR2 而不是 VARCHAR2(或将 NCLOB 而不是 CLOB)。 NVARCHAR2 是专门设计的,因此您可以处理多字节字符而无需修改主数据库字符集。有关 VARCHAR2 和 NVARCHAR2 之间的差异,请参阅这个问题 )。另请注意,某些应用程序可能无法与 NVARCHAR2 正常工作
  2. 您可以将该列修改为 RAW 或 BLOB,并直接将字符串写入为二进制流。当你再次读取它时,它仍然是 UNICODE 数据。然而,数据库很难对此列数据执行任何操作:排序将是二进制的,搜索将出现问题,因为您将无法正确使用 LIKE 运算符。
  3. 如果您有大量 UNICODE 输入,您可以考虑修改数据库字符集。这将是成本最高的选项(您可能需要导出/重新安装/导入),但之后所有列都将具有正确的数据类型。

如果可以选择的话,我会选择(1)或(3)。使用 RAW 会禁用许多功能并增加复杂性。

显然,仅使用数据库可用的数据无法恢复先前的数据:您必须在新结构中重新导入旧数据。

Strings inserted in a character (VARCHAR2 or CHAR or CLOB) column will always be converted to the database character set. This means that the inserted data is converted to WE8ISO8859P1 in your case. Since UNICODE is not a subset of WE8ISO8859P1, you will lose information. Some characters unavailable in your character set are transformed into ? upon insert.

What should you do? There are a couple of options for new data:

  1. Modify the datatype of the column to NVARCHAR2 instead of VARCHAR2 (or NCLOB instead of CLOB). NVARCHAR2 is specifically designed so you can handle multi-byte characters without modifying your main db character set. See this SO question for differences between VARCHAR2 and NVARCHAR2). Also be aware that some applications may not work correctly with NVARCHAR2.
  2. You could modify the column to a RAW or BLOB and write directly your string as a binary stream. When you read it again it will still be UNICODE data. It will be difficult for the database to do anything with this column data however: sorting will be binary, searching will be problematic as you won't be able to use the LIKE operator properly.
  3. If you have lots of UNICODE input, you could consider modifying your database character set. This would be the most costly option (you will probably need to export/reinstall/import) but afterwards all your columns will have the correct datatype.

I would go with option (1) or (3) if given the choice. Working with RAW disables a lot of features and adds complexity.

Obviously prior data will be impossible to restore with only the data available to the database: you will have to reimport old data in the new structure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文