I am searching for SSN number that was indicated in a Table with 4800 varchar.
I tried
SSN_MSG Like ‘%[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]%’
But it didn’t work. I need to check for the format of SSN which is SSN 000-00-0000
I am searching for SSN number that was indicated in a Table with 4800 varchar.
I tried
SSN_MSG Like ‘%[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]%’
But it didn’t work. I need to check for the format of SSN which is SSN 000-00-0000
From what I have read, DB2 version 11 should support REGEXP_LIKE
:
WHERE REGEXP_LIKE(SSN_MSG, '[0-9]{3}-[0-9]{2}-[0-9]{4}')
For earlier DB2 versions the fn:matches function can be used, which allows the same regular expression.
with tab (str) as (
select '123-45-6789' from sysibm.sysdummy1
union all
select '123456789' from sysibm.sysdummy1
)
select str
from tab
where xmlcast(xmlquery('fn:matches($s, "[0-9]{3}-[0-9]{2}-[0-9]{4}")' passing str as "s") as int)=1;
STR
-----------
123-45-6789