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\"
\
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