I have a table with a Phone_Numbers column. I want to delete all rows that do not have the exact length of 10 digits.
Asked
Active
Viewed 1,400 times
0
-
1First, you have to write a query. Try that and then come back if you have questions about that. That is, no one is going to write a query for you, especially based on an unknown schema with unknown constraints and unknown requirements. See [ask]. – Mar 07 '19 at 15:36
-
Possible duplicate of [querying WHERE condition to character length?](https://stackoverflow.com/questions/6807231/querying-where-condition-to-character-length) – Mat Mar 07 '19 at 15:49
1 Answers
0
Before asking a question you should try, and if you don't succeed please provide the code you wrote.
You can use the LENGHT fonction :
DELETE FROM table_name WHERE LENGTH(Phone_Numbers) != 10

Ianis
- 1,165
- 6
- 12
-
Phone numbers are subject to all kind of formatting "rules" want happens if the string contains a `000-000-00` format is to still a valid phone number? @Rakonu think about that because this query does not handle those "rules" – Raymond Nijland Mar 07 '19 at 15:46
-
You say that however you feed the answer anyway. Not the best way to make people stop asking for code don't you think ? – Mat Mar 07 '19 at 15:47
-
1Note that the MySQL `LENGTH` function returns a number of *bytes*, the `CHAR_LENGTH` function returns number of *characters*. (Those will be the same for single byte characterset such as latin1, but is not necessarily true for a multibyte characterset (e.g. utf8). I also strongly recommend testing with a SELECT statement, as a verification, before turning it into a DELETE statement. – spencer7593 Mar 07 '19 at 16:14