净BlockCopy和DB2字符转换使用codePAGE字符、BlockCopy、codePAGE

2023-09-07 08:58:49 作者:extreme(极端)

据我所知,整理可以在数据库中不同的表,设置不同。排序规则是由What确实字符集和校对规则意味着什么?

有执行 CAST 从一个字符效果如下图所示的查询。有没有涉及到的表。我猜想,申请编码将根据在数据库级别的排序规则。难道这个假设是正确的?

  SELECT CAST(SSS.id_encrypt('E','0000000 {0})AS CHAR(100)位数据)
AS ENCRYPT_ID从FFGLOBAL.ONE_ROW FETCH FIRST 1 ROW ONLY
 

在问题获取字节[]从DB2中没有编码给出了答案通过@AlexFilipovici [净 BlockCopy ]相比, CAST 的结果提供了一个不同的结果。为什么会这样,如果没有 codePAGE 相关?

根据国家语言支持 - 字符转换

  

位的数据(定义为FOR BIT DATA,或BLOB的,或二进制字符串列)不与任何字符集相关联。

参考

获取字节[]从DB2中没有编码 新数据库的默认code页面统一code 国家语言支持 - 字符转换 解决方案 我想把用UltraEdit打开的文件中的字符复制出来,可是好像不行啊

要回答你的问题:

#1:指定 FOR BIT DATA 亮(DB2)基于字符的数据类型,意味着DB2存储/返回原始数据传回没有codePAGE相关的(也就是说,它的字节只是一个字符串,不会通过客户端和服务器之间的任何codePAGE转换)。

#2:在DB2用于Linux,UNIX和Windows中,可以通过查询确定数据库的归类 SYSIBMADM.DBCFG

 选择名称,值
  从sysibmadm.dbcfg
 凡在('codePAGE','codeSET)的名称;
 

3:每@Iswanto三:

  SELECT DATABASEPROPERTYEX('数据库名称','整理');
 

I understand that collation can be set differently in different tables in a database. Collation is understood from What does character set and collation mean exactly?

There is a query that performs CAST from a char results as shown below. There are no tables involved. I guess, the encoding applied will be based on the collation in database level. Is this assumption correct?

SELECT  CAST ( SSS.id_encrypt ('E','0000000{0}') AS CHAR(100) FOR BIT DATA)  
AS ENCRYPT_ID FROM FFGLOBAL.ONE_ROW FETCH  FIRST 1 ROW ONLY

QUESTION

In the question Get Byte[] from Db2 without Encoding answer given by @AlexFilipovici [.Net BlockCopy ] provides a different result when compared to CAST result. Why is it so if there is no codepage associated?

Based on National language support - Character conversion

Bit data (columns defined as FOR BIT DATA, or BLOBs, or binary strings) is not associated with any character set.

REFERENCE

Get Byte[] from Db2 without Encoding Default code page for new databases is Unicode National language support - Character conversion

解决方案

To answer your questions:

#1: Specifying FOR BIT DATA on a character-based data type (in DB2) means that DB2 stores / returns the raw data back with no codepage associated (i.e. it's just a string of bytes and will not go through any codepage conversion between client and server).

#2: In DB2 for Linux, UNIX and Windows, you can determine the database's collation by querying SYSIBMADM.DBCFG

 select name,value
  from sysibmadm.dbcfg
 where name in ('codepage','codeset');

#3: Per @Iswanto San:

SELECT DATABASEPROPERTYEX('databasename', 'Collation');