Home > Blockchain >  Snowflake SQL - Format Phone Number to 9 digits
Snowflake SQL - Format Phone Number to 9 digits

Time:03-12

I have a column with phone numbers in varchar, currently looks something like this. Because there is no consistent format, I don't think substring works.

(956) 444-3399 964-293-4321 (929)293-1234 (919)2991234

How do I remove all brackets, spaces and dashes and have the query return just the digits, in Snowflake? The desired output:

9564443399 9642934321 9292931234 9192991234

CodePudding user response:

You can use regexp_replace() function to achieve this:

REGEXP_REPLACE(yourcolumn, '[^0-9]','')

That will strip out any non-numeric character.

CodePudding user response:

You could use regexp_replace to remove all of the special characters

something like this

select regexp_replace('(956) 444-3399', '[\(\) -]', '')

CodePudding user response:

An alternative using translate . Documentation

 select translate('(956) 444-3399', '() -', '')
  • Related