Nerd alert: Finding non-printing characters in varchar2 fields in Oracle

How to find non printing characters using instr and regexp_instr in Oracle databases:

Example 1
Prints first location of non-printing text and the value of the column:

select 
    regexp_instr(a.COL_NAME,'[^[:print:]]') as STRING_POSITION,
    a.COL_NAME
from
    TABLE_NAME a
where
    regexp_instr(a.COL_NAME,'[^[:print:]]') > 0    
;

Example 2
To focus on one of the more common non-printing characters, this query will find line feed/carriage returns in a field:

select
    a.COL_NAME
from
    TABLE_NAME a 
where
    instr(a.COL_NAME, chr(13)) != 0
    or instr(a.COL_NAME, chr(10)) != 0 
;

Group and filter as needed…

This entry was posted in oracle/sqlserver/database. Bookmark the permalink.

1 Response to Nerd alert: Finding non-printing characters in varchar2 fields in Oracle

  1. Alexis says:

    old… but really helpful! 🙂

    thanks for the tip!

Leave a Reply

Your email address will not be published. Required fields are marked *