Home > Back-end >  How to add plus( ) sign in every row of a column using SQL query?
How to add plus( ) sign in every row of a column using SQL query?

Time:05-21

I have a database with a column containing phone numbers. I want to add plus( ) sign in the beginning of every phone number.

UPDATE Table 
SET Phone = CONCAT(' ', Phone)

This is the query I'm using to insert any other character, but it doesn't seem to work with sign. It says 0 row(s) affected Rows matched: 4023 Changed: 0 Warnings: 0, which means nothing has changed.

Even if I do SET Phone = CONCAT(' 91', Phone), only 91 is being inserted and not the plus sign.

CodePudding user response:

I think I understood what's going on here. Your Table is probably using integer data type for Phone column. In this case Phone = CONCAT(' 91', Phone) implicitly converts value to character type, adds leading " " but then converts it back to integer type to store value.

You might want to do something like

ALTER TABLE `Table` MODIFY Phone Varchar(100);

(please choose column type accordingly)

I reproduced it here http://sqlfiddle.com/#!9/5b3a651/1

  • Related