How to find special characters in DB2?

前端 未结 6 851
北海茫月
北海茫月 2020-12-06 07:22

I have a DB2 database containing millions of records. I found that some char() or varchar() fields contain special characters which shouldn\'t be stored. I guess application

6条回答
  •  一向
    一向 (楼主)
    2020-12-06 07:42

    I know this is an older thread...but after reading a ton...this was my exact problem and here is the solution I came up with to determine the problem rows...so that I could go in and manually fix them. FYI - the problem for me happens because users are copy/pasting from Word into my app. Yes I know we should fix that before ever saving...but we have bigger fish to fry.

    SELECT * FROM TABLE_A where ASCII(TRIM(TRANSLATE( COLUMN_A, ' ', -- empty string '()<>!;%$#*?@+&^=-":/''.,0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ))) not in (10,64)

    Some Notes:

    • We use iSeries DB2 and this works great
    • Make sure to keep all the spaces intact in the translate function...it needs 1 space for ever character you use
    • In the 3rd parameter of the translate function there are 2 single quotes next to each other and the first one simply escapes the other (for those that may not know)

提交回复
热议问题