简体   繁体   中英

Teradata: Best way to search items using wildcard

I'm trying to search items using where clause like this:

SELECT *
FROM TABLE
WHERE ITEMID LIKE '%[0-9][abc][0-9]%'

What I am trying to achieve is to retrieve data having itemID with alphabets of only 'a' , 'b' , or 'c' , starting and ending with number in the middle of alphanumerical value.

For instance, '337Z112' shouldn't be retrieved because it is not 'a' , 'b' , or 'c' .

Other example is 'edcb9a9b' which should be retrieved because it contains '9a9' .

Thanks in advance!

In Teradata, you would need to use REGEXP_SIMILAR() to compare agains a regular expression:

SELECT *
FROM mytable
WHERE RegExp_Similar(itemid, '.*\d[abc]\d.*', 'i') = 1;

NB : \\d is a shortcut for [0-9] (the digits character class)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM