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 extract only numbers from string in mysql

I have a data like under mentioned in table in one column name remarks

Will0017,Will0018, Kind0045 , DGRG0012

I want to extract only numbers from the same only like 0017,0018,0045,0012

How can I do the same in mysql.

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

I have tried like this

select reject_remarks,regexp_substr(reject_remarks,"[0-9]+")  from table; 

but have anything like I want

I have tried like this

select reject_remarks,regexp_substr(reject_remarks,"[0-9]+")  from table ;

>Solution :

you can use REGEXP_REPLACE where ou negate all possible allowed characters

CREATE Table mytable(reject_remarks varchar(100))
INSERT INTO mytable VALUES ('Will0017,Will0018, Kind0045 , DGRG0012')
SELECT  REGEXP_REPLACE(reject_remarks, '[^0-9,[:space:]]+', '') AS numbers 
FROM mytable;
numbers
0017,0018, 0045 , 0012

fiddle

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