Question

I have a mysql database column named like telephoneNo

Telephone No 
25645656
45454545
45565656

I want to prepend two digits XX to every value of telephoneNo column

Telephone No 
xx25645656
xx45454545
xx45565656

I was trying to workout with concat but its not with integer values in my case please help with update query

Was it helpful?

Solution

You can use CAST() to convert your integers explicitely:

UPDATE t SET phone=CAST(CONCAT('10', phone) AS UNSIGNED)

That will work with integer prefixes. However, I don't see solid reason to store phone numbers as integers and not strings

OTHER TIPS

That's a hack change your col to varchar or something.

UPDATE table SET telephoneNo=9200000000+telephoneNo;

EDIT:

This method requires that all your numbers are of the same length, and 8 digits long, if all your numbers are more or less than 8 digits modify the number of 0's after the 92 accordingly

If your telephone column is int, you can use concat string function to concat with int or string even like below

SELECT CONCAT(xx, telephone);

(OR)

SELECT CONCAT('xx', telephone);

(OR)

Explicitly cast your int column value

SELECT CONCAT('xx', CAST(telephone AS CHAR));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top