Display only landline and cell phones with digit 9 in front

-1

Next

I have a table named telefonia_numero and inside it there is a field called Numero where it contains all the user's phone.

  

Ex. Jose - Number 81 3636-1145, 81 99873-7787 and 9873-7787,

Here comes what I want.

I want to get only the fixed phone and the cell phones that has the digit 9 in front ex. (81 99873-7787). > And it would leave out what a nine to front menus Ex (9873-7787) would then get the landlines and the new phones with digit 9 in front.

    
asked by anonymous 21.03.2016 / 19:46

1 answer

0

You can use the replace() and char_length() functions of MySQL to substitute whitespace and nothing and count the number of characters in the phone and check that it has 11 digits in WHERE as follows:

//O primeiro parênteses verifica se é celular
SELECT * FROM telefones
WHERE (substr(replace(telefone, ' ', ''), 3,1) = 9 AND
CHAR_LENGTH(REPLACE(telefone, ' ', '')) = 12) OR CHAR_LENGTH(REPLACE(telefone, ' ', '')) = 11
    
21.03.2016 / 19:58