Reputation: 1
I have a column that has plain text data. I am looking to find any name that is followed by an integer 'Sam 123', Sam 597" etc.
I have tried
SELECT message, LENGTH(message)
FROM surveys
WHERE LENGTH(MESSAGE) = 6
but it returns alphanumeric data.
Upvotes: 0
Views: 60
Reputation: 12339
For all DB2 versions:
select message
from table(values 'Sam 123', 'Sam 597', 'Sam123', 'Sam', '123 Sam') t(message)
where xmlcast(xmlquery('fn:matches($s, "[a-zA-Z]+ [0-9]+")' passing t.message as "s") as int) = 1
Upvotes: 1
Reputation: 48865
Starting on DB2 11.1 you can use regular expressions. Your query should look like:
select message, length(message)
from surveys
where regexp_like(message, '[a-zA-Z]+ [0-9]+')
This regular expression matches:
Upvotes: 1