Connecting Tech Pros Worldwide Help | Site Map

pattern matching

jrhoad@hotmail.com
Guest
 
Posts: n/a
#1: Nov 21 '07
Is there any way to do the following pattern match in db2?

LIKE '[CK]ars[eo]n' searches for Carsen, Karsen, Carson, and Karson
(Carson).

In other words, the brackets around CK will match anything with a C or
K in the first character.

Thanks.
Lennart
Guest
 
Posts: n/a
#2: Nov 21 '07

re: pattern matching


On Nov 21, 3:10 pm, jrh...@hotmail.com wrote:
Quote:
Is there any way to do the following pattern match in db2?
>
LIKE '[CK]ars[eo]n' searches for Carsen, Karsen, Carson, and Karson
(Carson).
>
In other words, the brackets around CK will match anything with a C or
K in the first character.
>
Thanks.
For simple patterns you can use something like:

select * from T where substr(mycol,1,1) in ('C','K') and substr(mycol,
2,3) = 'ers' ...

For a more general approach, you might find the following article by
Knut Stolze interesting:

http://www.ibm.com/developerworks/db...301stolze.html

/Lennart
Closed Thread