如何在db2查询中将字符集转换为unicode

时间:2017-09-19 16:11:20

标签: unicode db2 ebcdic

服务器:运行DB2的IBM i Series AS / 400

客户端:Linux使用unixodbc

我在DB2数据库中有一个表,其中包含一列使用CCSID 836(简体中文EBCDIC)的数据。我希望得到UTF-16的结果,因此它们可以在其他系统上运行,但我很难找到正确的转换方法。

当我尝试:

SELECT CAST(MYCOLNAME AS VARCHAR(100) CCSID 13491) FROM MY.TABLE

我收到错误:

SQL State: 22522
Vendor Code: -189
Message: [SQL0189] Coded Character Set Identifier 13491 not valid. Cause . . . . . :  Coded Character Set Identifier (CCSID) 13491 is not valid for one of the following reasons: -- The CCSID is not EBCDIC. -- The CCSID is not supported by the system. -- The CCSID is not vaid for the data type. -- If the CCSID is specified for graphic data, then the CCSID must be a DBCS CCSID. -- If the CCSID is specified for UCS-2 or UTF-16 data, then the CCSID must be a UCS-2 or UTF-16 CCSID. -- If the CCSID is specified for XML data, then the CCSID must be SBCS or Unicode. It must not be DBCS or 65545.

如何将数据从CCSID 836转换为UTF-16?我UNICODE_STR()同样失败了。

1 个答案:

答案 0 :(得分:1)

我无法解释原因,但这里有效:

SELECT CAST(MYCOLNAME AS VARCHAR(100) CCSID 935) FROM MY.TABLE

相关列的原生CCSID是836,看起来与935非常相似,所以我不明白其中的区别。但935对我有用。