0

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

Mark Barinstein
  • 11,456
  • 2
  • 8
  • 16

2 Answers2

0

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}')
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Db2 for LUW and DB2 for Z/OS are different products. [REGEXP_LIKE](https://www.ibm.com/support/knowledgecenter/en/SSEPEK_12.0.0/sqlref/src/tpc/db2z_bif_regexplike.html) function you mentioned is supported starting from V12 there. – Mark Barinstein Mar 14 '19 at 03:53
  • @MarkBarinstein Well in this case maybe the OP would have to resort to using a user defined function. – Tim Biegeleisen Mar 14 '19 at 04:09
0

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
Mark Barinstein
  • 11,456
  • 2
  • 8
  • 16