Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

sql - Remove Accents DB2

Does someone knows how to get rid of accents words in DB2 ?

I got that one bellow :

select UPPER(  'test'  || 'DescricaoDomino' || NVL('SiglaDomino', 'X')) from tbProcTeste  ;

And i got that result :

 1
 -------------------------------

     TESTDESCRICAODOMINOSIGLADOMINO

However i could receive a string with accents like this one "!":

      select UPPER(  'test!'  || 'DescricaoDomino' || NVL('SiglaDomino', 'X')) 
from  tbProcTeste  ;

And id like to get a same result above . Someone knows how do i do that ?

Result that i expected

1


 TESTDESCRICAODOMINOSIGLADOMINO

I dont have huge DB2 background . DB2 Version 11,1

Sincerly

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Based on the mapping in this post https://stackoverflow.com/a/9667817/9525344 the following Db2 function will replace most(?) of the possible Unicode characters with diacritic marks with their simple Latin equivalent (which may, or may not be what is actually used as a replacement in a given language. E..g in German, ü is usually replaced with ue, not u)

CREATE OR REPLACE FUNCTION DB_STRIP_DIACRITICS(string VARCHAR(32000))
RETURNS VARCHAR(32000)
LANGUAGE SQL CONTAINS SQL DETERMINISTIC NO EXTERNAL ACTION
RETURN
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(
 string,
'[á??????ǎ????????????à??ā????????]',                  'A'), 
'[?]',                                                 'AA'), 
'[????]',                                              'AE'), 
'[?]',                                                 'AO'), 
'[?]',                                                 'AU'), 
'[??]',                                                'AV'), 
'[?]',                                                 'AY'), 
'[????????]',                                          'B'), 
'[??????????]',                                        'C'), 
'[?????????????]',                                     'D'), 
'[??]',                                                'DZ'), 
'[é?ě??ê??????????è??ē??????????]',                    'E'), 
'[?]',                                                 'ET'), 
'[????]',                                              'F'), 
'[????????????]',                                      'G'), 
'[??????????]',                                        'H'), 
'[í?ǐ??????ì??ī?????]',                                'I'), 
'[?]',                                                 'IJ'), 
'[?]',                                                 'IS'), 
'[???]',                                               'J'), 
'[???????????]',                                       'K'), 
'[?????????????????]',                                 'L'), 
'[?]',                                                 'LJ'), 
'[??????]',                                            'M'), 
'[??????????????]',                                    'N'), 
'[?]',                                                 'NJ'), 
'[ó?ǒ?????????????ò??????????ō??????????????]',        'O'), 
'[??]',                                                'OE'), 
'[?]',                                                 'OI'), 
'[?]',                                                 'OO'), 
'[??]',                                                'OU'), 
'[????????]',                                          'P'), 
'[??]',                                                'Q'), 
'[????????????????]',                                  'R'), 
'[????????????]',                                      'S'), 
'[?????????????]',                                     'T'), 
'[?]',                                                 'TZ'), 
'[ú?ǔ??üǘǚǜǖ????ù????????ū???????]',                   'U'), 
'[??????]',                                            'V'), 
'[?]',                                                 'VY'), 
'[????????]',                                          'W'), 
'[??]',                                                'X'), 
'[Y????????????]',                                     'Y'), 
'[??????????]',                                        'Z'), 
'[á??????ǎa???????????à??ā??????????]',                'a'), 
'[?]',                                                 'aa'), 
'[????]',                                              'ae'), 
'[?]',                                                 'ao'), 
'[?]',                                                 'au'), 
'[??]',                                                'av'), 
'[?]',                                                 'ay'), 
'[????????]',                                          'b'), 
'[???????????]',                                       'c'), 
'[???????????????]',                                   'd'), 
'[??]',                                                'dz'), 
'[é?ě??ê??????????è??ē?????????????]',                 'e'), 
'[?]',                                                 'et'), 
'[?????]',                                             'f'), 
'[?]',                                                 'ff'), 
'[?]',                                                 'ffi'), 
'[?]',                                                 'ffl'), 
'[?]',                                                 'fi'), 
'[?]',                                                 'fl'), 
'[???????????ɡ?]',                                     'g'), 
'[??????????????]',                                    'h'), 
'[?]',                                                 'hv'), 
'[?í?ǐ?????ì??ī???????]',                              'i'), 
'[?]',                                                 'ij'), 
'[?]',                                                 'is'), 
'[????????]',                                          'j'), 
'[????????????]',                                      'k'), 
'[??????????????????]',                                'l'), 
'[?]',                                                 'lj'), 
'[????????]',                                          'm'), 
'[ńň?????????????]',                                   'n'), 
'[?]',                                                 'nj'), 
'[?ó?ǒ?????????????ò???????????ō???????????????]',     'o'), 
'[??]',                                                'oe'), 
'[?]',                                                 'oi'), 
'[?]',                                                 'oo'), 
'[?]',                                                 'ou'), 
'[?????????]',                                         'p'), 
'[????]',                                              'q'), 
'[???????????????????????]',                           'r'), 
'[???????????????????]',                               's'), 
'[?]',                                                 'st'), 
'[?????????????????]',                                 't'), 
'[?]',                                                 'th'), 
'[?]',                                                 'tz'), 
'[?ú?ǔ??üǘǚǜǖ????ù????????ū????????]',                 'u'), 
'[?]',                                                 'ue'), 
'[?]',                                                 'um'), 
'[?????????]',                                         'v'), 
'[?]',                                                 'vy'), 
'[?????????]',                                         'w'), 
'[????]',                                              'x'), 
'[?y????????????]',                                    'y'), 
'[??????????????]',                                    'z')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...