I would like to apply for phone numbers in MySQL

5

I need help

As in SQL you can format phone numbers, with a

N_Cel varchar(8) check((N_Cel)like '[2|7|8|5][0-9][0-9][0-9][0-9][0-9][0-9][0-9]') NOT NULL,

I want to do the same in MySQL but it makes a mistake, could someone explain to me?

Thanks in advance

    
asked by Carolina Lumbí 29.06.2018 в 23:39
source

2 answers

5

Try this: (Works on S QL Server )

UPDATE TheTable
SET PhoneNumber = SUBSTRING(PhoneNumber, 1, 3) + '-' + 
                  SUBSTRING(PhoneNumber, 4, 3) + '-' + 
                  SUBSTRING(PhoneNumber, 7, 4)

CREATE FUNCTION FormatPhoneNumber(@phoneNumber VARCHAR(10))
RETURNS VARCHAR(12)
BEGIN
    RETURN SUBSTRING(@phoneNumber, 1, 3) + '-' + 
           SUBSTRING(@phoneNumber, 4, 3) + '-' + 
           SUBSTRING(@phoneNumber, 7, 4)
END
    
answered by 30.06.2018 / 00:54
source
1

It actually worked for me with just the update of my table

update empleados
set N_Cel = substring(N_Cel,1,3) + '-' +
        substring(N_Cel,4,3) + '-' 

If someone gave you the code 1175 error to disable the secure update, you should only:

SQL_SAFE_UPDATES=0;

Thanks:)

    
answered by 30.06.2018 в 05:07