Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2015
    Posts
    3

    Lightbulb Unanswered: How to find non-ASCII symbols in a string

    Hi everyone,
    please advise on my particular issue.

    I have a table field with VARCHAR type. I need to validate this field the way it DOESN'T have any non-ASCII symbols (like ╥ ї ╡ etc.) I didn't find any ways to resolve this issue.

    Please give me a hand in this. Thanks in advance!

    P.S. DB2 v9.7 (AIX)
    Last edited by sairus; 09-09-15 at 08:42.

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    maybe by use of hex() function and specifying some limts
    check infocenter for details about syntax
    ps : as stated in thread : must read before posting : always specify db2 level and platform because the syntax is depending on this
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Note that this assumes that you're running DB2 on an ASCII (non z/OS) machine.

    This is pure "air code", so it might have minor syntax errors:
    Code:
    DECLARE nonascii_like_expr VARCHAR(99);
    SET nonascii_like_expr = '%[' || Chr(1) || '-' || Chr(31) || Chr(128) || '-' || Chr(255) || ']%';
    
    SELECT *
       FROM yourTableNameHere
       WHERE  yourColumnNameHere NOT LIKE nonascii_like_expr;
    This ought to return all of the valid (pure ASCII characters in yourColumnNameHere) rows.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Sep 2015
    Posts
    3
    Quote Originally Posted by Pat Phelan View Post
    Note that this assumes that you're running DB2 on an ASCII (non z/OS) machine.

    This is pure "air code", so it might have minor syntax errors:
    Code:
    DECLARE nonascii_like_expr VARCHAR(99);
    SET nonascii_like_expr = '%[' || Chr(1) || '-' || Chr(31) || Chr(128) || '-' || Chr(255) || ']%';
    
    SELECT *
       FROM yourTableNameHere
       WHERE  yourColumnNameHere NOT LIKE nonascii_like_expr;
    This ought to return all of the valid (pure ASCII characters in yourColumnNameHere) rows.

    -PatP
    Hi Pat,
    seems like your code is not working properly:

    Code:
    select  
      case 
        when '%[' || Chr(1) || '-' || Chr(31) || Chr(128) || '-' || Chr(255) || ']%' = '╞' <--- // this is a test value ;
        then 'Y'
        else 'N' 
        End
      from sysibm.sysdummy1 with ur for read only;
    The return result is always 'N' - whatever stands for test value...

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by sairus View Post
    seems like your code is not working properly: The return result is always 'N' - whatever stands for test value...
    Check my example again. I'd suggest that you try using the LIKE predicate as I did instead of the equals predicate.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  6. #6
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    try this:
    Code:
    select t.str
    from table(values 'abc~', 'de╥ї╡f') t(str)
    where xmlcast(xmlquery('fn:matches($s, "[^\x00-\xFF]")' passing t.str as "s") as int)=1
    
     STR
     ------
     de╥ї╡f
    Regards,
    Mark.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •