Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite replace() for replacing multiple characters

Tags:

android

sqlite

I have database table Contacts with columns Mobile, officePhone.

Here users will save data as follows.

mobile=+91 (937) 2582 6433
officephone= (843)-6486-6783

Now i need to retrieve phone numbers with out any special characters

Some how i found following query,

Select REPLACE(mobile,'+','') as mobile , REPLACE(officePhone,'+','') as officePhone from Contacts;

This will remove only "+" symbol but i want to remove all special symbols including space. Please help me in this regard.

like image 846
user3363533 Avatar asked Oct 30 '25 07:10

user3363533


1 Answers

It's not exactly pretty, but you could nest the replace() functions:

replace(replace(replace(replace(mobile,' ',''),'-',''),'(',''),')','')

Agreed, if possible you can format outside of sqlite, but that is not always wanted/possible. E.g. I had a case where the replaces were needed for the WHERE part.

like image 146
wivku Avatar answered Oct 31 '25 21:10

wivku



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!