How to count the number of numerical values in a string

There is a column in a string format. Data in that column is a mixture of letters and numbers. I want to pick up rows which contain more than 4 numbers in it.

For example, in the table below, what I’m interested in is row_num 4 as it contains more than 4 numerical values. How can they be selected?

row_num column_1
1 fje8q934yeufoeha
2 08kfdjaehewaoffe
3 6fdiuewwiaei3eew
4 jfe0293ujfid22fe

>Solution :

We can use a regex replacement here:

SELECT row_num, column_1
FROM yourTable
WHERE LENGTH(REGEXP_REPLACE(column_1, '\D+', '')) > 4;

Leave a Reply