Insert a comma in address field before number of house

前端 未结 1 1851
自闭症患者
自闭症患者 2021-01-27 12:08

I have a table with a lot of address field that have no comma between street name and house number. Something like:

\"VIA MILANO 123\"
\"VIA MILANO    A123\"
\         


        
相关标签:
1条回答
  • 2021-01-27 13:08

    Db2 for i 7.2 supports the REGEXP_REPLACE function

    https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/db2/rbafzscaregexp_replace.htm

    Try this

    SELECT c, REGEXP_REPLACE(c,'(\s+\S*\d+\s*$)',',\1') 
    FROM TABLE(
        VALUES
         ('VIA MILANO 123     ')
        ,('VIA MILANO A123    ')
        ,('VIA 11 MILANO AA123')
    ) AS t(c)
    

    returns

     C                      2
     -------------------    --------------------
     VIA MILANO 123         VIA MILANO, 123
     VIA MILANO A123        VIA MILANO, A123
     VIA 11 MILANO AA123    VIA 11 MILANO, AA123
    

    Regular Expressions provide a powerful and flexible way to manipulate strings , and it is worth learning about them.

    https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/db2/rbafzregexp_like.htm#rbafzregexp_like__regexp_likecontrol

    0 讨论(0)
提交回复
热议问题