Rocky
Rocky

Reputation: 35

Search for numbers in a string

I am using teradata 15, and want to search those rows which contains 4 digit number in a varchar column.I tried to use below:

column1 like '[^0-9][0-9][0-9][0-9][0-9][^0-9]'

but it didn't help. Any help will be helpful.

Thanks,

Upvotes: 0

Views: 2370

Answers (1)

dnoeth
dnoeth

Reputation: 60462

Teradata only supports Standard SQL LIKE, but there's REGEXP_SIMILAR, too. This is your LIKE as regex:

where regexp_similar(column1, '[^0-9][0-9]{4}[^0-9]') = 1

Edit:

Based on your added example you want to find at least for consecutive digits within an arbitrary string:

regexp_similar(column1, '.*[0-9]{4,}.*')

Upvotes: 4

Related Questions