lkhiger
New User
Joined: 28 Oct 2005 Posts: 89
|
|
|
|
Another way to cleanup string from unreadable characters.
For example we have to remove from the string all characters with hexadecimal code less then X'40' (space).
We can do this in following way:
Code: |
With
Source (source_str) as
(select 'Wel' || X'00070d33' || 'come ' || X'33343f' || 'to DB2 !'
from sysibm.sysdummy1
)
,
Clean_up(source_str, result_str, posn, maxposn) as
(select source_str, varchar('', length(source_str)), 0, length(source_str)
from Source
Union All
select source_str,
result_str || case When substr(source_str, posn + 1, 1) < X'40' Then ''
Else substr(source_str, posn + 1, 1) End,
posn + 1, maxposn
From Clean_up Where posn + 1 <= maxposn
)
select source_str as "Source string", result_str "Result String"
From Clean_up
Where posn = maxposn |
|
|