简体   繁体   English

如何在DB2中查找所有具有Unicode字符的记录

[英]How to find all the records having unicode character in DB2

I know there are other similar questions but they are specific to certain special characters. 我知道还有其他类似的问题,但它们特定于某些特殊字符。 I am looking for a solution by which i can filter out all the records having unicode character in a column in DB2 我正在寻找一种解决方案,通过该解决方案,我可以过滤出DB2列中具有Unicode字符的所有记录

As mustaccio said, all chars are unicode. 正如mustaccio所说,所有字符都是unicode。

Probably, you are having problems when using text characters from other languages. 使用其他语言的文字字符时,可能会遇到问题。 It is very common that native-english speakers do not understand the problem of other characters, because the 26 character are standard in all encodings. 母语为英语的人不理解其他字符的问题是很常见的,因为26个字符在所有编码中都是标准的。

If you are having that problem, you have to formulate your problem in another way. 如果您遇到该问题,则必须以另一种方式提出问题。 Something like: 就像是:

Taking all unicode characters as a set, I would like to know which characters fall outside the subset of the valid letters in my language (spanish in my case). 以所有unicode字符为一组,我想知道哪些字符不在我的语言中有效字母的子集范围内(在我的情况下为西班牙语)。

With this in mind, you can query your data, and perform an analysis of which values are not part of your language. 考虑到这一点,您可以查询数据,并分析哪些值不属于您的语言。 You can do that with a regular expression. 您可以使用正则表达式执行此操作。

CREATE OR REPLACE FUNCTION ENCODING_VALIDATION_SPANISH (
 IN TEXT VARCHAR(256) 
) RETURNS VARCHAR(32)
LANGUAGE SQL
PARAMETER CCSID UNICODE
SPECIFIC F_ENC_VAL_SP
DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
F_ENC_VAL_SP: BEGIN
  DECLARE RET VARCHAR(32);
  SET RET = XMLCAST (
    -- The next line define the valid characters for the Spanish language.
    XMLQUERY ('fn:matches($TEXT,"^[A-Za-z\- \.,\?\u00C1\u00E1\u00C9\u00E9\u00CD\u00ED\u00D3\u00F3\u00DA\u00FA\u00DC\u00EC\u0147\u0148]*$")' 
      PASSING TEXT AS "TEXT"
  ) AS VARCHAR(32));
  RETURN RET;
END F_ENC_VAL_SP @

I wrote an article, where I explain that problem: http://angocadb2.blogspot.fr/2013/09/validate-encoding-problems-in-db2.html 我写了一篇文章,在那里我解释了这个问题: http : //angocadb2.blogspot.fr/2013/09/validate-encoding-problems-in-db2.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM