I need to clean phone numbers stored as varchar. There is bad data where unknown phone numbers are stored as a sequence of a single digit. Eventually more complex (area code & prefix matching) will be done but I want a simply query to obviously bad records.
So for example:
Valid Phone Number: 3289903829
Invalid Phone Number: 1111111111
Now if the bogus Product ID are the proper length ( 10 digits) it is easy to parse and clean.
SELECT phone
FROM customers
SET phone = NULL
WHERE phone IN ('0000000000','9999999999',''8888888888','7777777777','6666666666','5555555555','4444444444','3333333333','2222222222','1111111111')
However sometimes the bogus phones are of arbitrary length (likely due to typos) so 11 ones or 9 ones, or n ones.
How can I ID strings that consists of all of the same char/digit?
1111111 - match
4444 - match
1112 - no match
4445555 - no match
You can get the first character and replicate it: