Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We can use a regex replacement here:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading